mainloop()会接管主程序,请问如何让mainloop()之后的程序接着跑?
root = Tk()
listbox = Listbox(root)
listbox.pack(fill=BOTH, expand=True)
for i in range(10):
listbox.insert(END, str(i))
mainloop() #mainloop()会接管主程序,请问如何让mainloop()之后的程序接着跑?
print('窗口创建完成')
改造成多线程
import tkinter as tk
import threading
def xiancheng1():
root = tk.Tk()
listbox = tk.Listbox(root)
listbox.pack(fill=tk.BOTH, expand=True)
for i in range(10):
listbox.insert(tk.END, str(i))
tk.mainloop() #mainloop()会接管主程序,请问如何让mainloop()之后的程序接着跑?
def xiancheng2():
print('窗口创建完成')
if __name__ == '__main__':
t1=threading.Thread(target=xiancheng1)
t1.start()
t2=threading.Thread(target=xiancheng2)
t2.start()
页:
[1]