python gui 多进程的疑问

from tkinter import *
import concurrent.futures


def p1():
    while True:
        print('1')


def p2():
    while True:
        print('2')


def login():
    login_window.after(1, p1)
    login_window.mainloop()


def main():
    main_window.after(1, p2)
    main_window.mainloop()


if __name__ == '__main__':
    login_window = Tk()
    login()
    main_window = Tk()
    main()
    with concurrent.futures.ProcessPoolExecutor() as executor:
        executor.submit(login)
        executor.submit(main)

如上所示,在Python中如何能够同时运行两个窗口,互不干扰地执行自己的任务。

———————————————————————————————————————————————————

感谢@同意并接受的回答,我修改成了下面这样,但是还是一直输出1。

from tkinter import *
import time


def p1():
    while True:
        print('1')
        time.sleep(1)


def p2():
    while True:
        print('2')
        time.sleep(1)


def main():
    login_window.after(1, p1)
    main_window.after(1, p2)
    main_window.mainloop()


if __name__ == '__main__':
    main_window = Tk()
    login_window = Toplevel()
    main()
哔哔one
浏览 460回答 1
1回答
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Python