【发布时间】:2020-05-30 12:36:17
【问题描述】:
以下是我用来运行两个 python 文件的主要功能,但是一旦我单击按钮,我的窗口就会冻结。请告诉我一种执行多线程的方法,以便我可以同时单击两个按钮。
import pandas as pd
import numpy as np
from tkinter import *
from tkinter.ttk import *
from tkinter import messagebox
import threading
import Test1
import Test2
# In[ ]:
def Load1():
Test1.func()
messagebox.showinfo( "Successful","Reconcilation Complete")
def Load2():
Test2.func()
try:
messagebox.showinfo( "Successful","Reconcilation Complete")
except Exception as inst:
messagebox.showinfo( "Unsuccessful",inst)
root = Tk()
root.geometry('375x100')
root.title("Reco")
root.configure(background="LightBlue2")
style = Style()
style.configure('TButton', background = 'SeaGreen2', font =
('calibri', 20, 'bold'))
btn1 = Button(root, text = 'Tier Recon', command =threading.Thread(target=Load1).start )
btn1.grid(row = 1, column = 3, pady = 10, padx = 100)
btn2 = Button(root, text = 'View Recon', command =threading.Thread(target=Load2).start)
btn2.grid(row = 2, column = 3, pady = 10, padx = 100)
root.mainloop()
【问题讨论】:
-
在你的其他脚本中你又调用了 tk.Tk 吗?
-
请修正发布代码的格式。
标签: python multithreading tkinter