如果我第二次調用這個類,鍵盤焦點首次進入窗口。第二次沒有。退出鍵用於關閉窗口,它首次運行。第二次必須在退出鍵工作之前用鼠標點擊窗口。有沒有傳遞的焦點沒有被傳回?我遇到過這個問題很多次,但在這裏我儘可能地簡單了。下面的代碼:第二次對Python應用程序的調用怎麼沒有鍵盤焦點
from Tkinter import *
class Dialog(): # imagine this having buttons and stuff
def __init__(self):
root = Tk()
root.bind_all('<Escape>', lambda event :root.destroy())
root.mainloop()
# this simulates running a python terminal app which invokes a dialog at some point
Dialog() # this one accepts the key action
Dialog() # this one needs a mouse click in the window first
但是,爲什麼你會退出應用程序只是爲了重新啓動它? – 2011-01-27 11:19:09