【发布时间】:2019-09-30 17:07:25
【问题描述】:
当我按下按钮时,scan_open_ports 开始工作,直到 ip_list.curselection() 行停止,该行阻止了函数的运行... 我想知道为什么以及如何解决这个问题? 谢谢
def scan_open_ports():
#long runtime function
print "Asdasd\"
ip_list.curselection()
def thr_open_ports():
threading.Thread(target=scan_open_ports).start()
ip_list = Listbox()
scan_ports = Button(window, text="Scan Open Ports", command= thr_open_ports, height = 10, width = 20)
【问题讨论】:
-
你在stackoverflow上找到合适的代码了吗?
-
也许您可以使用指向该问题/答案的链接以及您说按钮卡住的您自己的代码文本来更新您的问题。
-
好吧,我认为
tkinter本身并不是多线程的。要与tkinter交流,我认为您必须使用队列并使用某种机制来轮询该队列并随后对其进行处理。 -
我试过使用队列,但还是不行……你有什么比线程更好的主意吗?
-
如果您的功能需要很长时间才能运行,并且您仍然需要 GUI 做出响应,则不需要。
标签: python multithreading function user-interface tkinter