1
我對Python比較陌生,特別是tkinter的新手。在以下示例代碼中,直接創建對話框(左按鈕)時對話框工作正常,但如果對話框是從線程(右按鈕)創建的,則應用程序變得無響應。什麼似乎是問題?線程可以啓動對話框嗎?如果是這樣,怎麼樣?來自線程的Python 3.0 tkinter對話框
from tkinter import *
from tkinter import ttk
import threading
count = 0
def makeDialog():
global count
count = count + 1;
messagebox.showinfo('Click Counter','Click #{0}'.format(count))
def makeThread():
threading.Thread(target=makeDialog).start()
root = Tk()
root.title("Dialogs")
mainframe = ttk.Frame(root)
mainframe.grid(column=0, row=0)
mainframe.columnconfigure(0, weight=1)
mainframe.rowconfigure(0, weight=1)
button1 = ttk.Button(mainframe, text="Dialog", command=makeDialog)
button1.grid(row=1, column=1)
button2 = ttk.Button(mainframe, text="Thread Dialog", command=makeThread)
button2.grid(row=1, column=2)
root.mainloop()
謝謝,內德。不知何故,我在最初的搜索中錯過了這個問題。它確實直接解決了我的問題。謝謝! – ProfPlum 2011-03-29 10:30:54