键盘不能在Toplevel python中直接使用

时间:2017-05-18 19:56:35

标签: python tkinter keyboard window toplevel

我正在使用Toplevel生成两个窗口。但是当它打开第二个窗口时,键盘不会立即激活(两个窗口同时打开),我需要先点击第二个窗口才能使用键盘。我尝试使用root.lift来修复它,但它不起作用。这有什么问题?

我的代码:

class practisePage1():
       def __init__(self, master):
           self.master = master
           self.master.update_idletasks()
           self.master.attributes('-fullscreen', True)  
           self.button1 = Button(self.master, text="NEXT", bg='gray77',   command=self.gotoPage3, anchor=CENTER)
           self.button1.pack()   

       def gotoPage1(self):
           self.root1 = Toplevel(self.master)
           self.instPage1 = practisePage1(self.root1)

class practisePage1():
       def __init__(self, master):
           self.master = master
           self.master.update_idletasks()
           self.master.attributes('-fullscreen', True)

           self.choiceA = master.bind('a', self.showResultEx1)  #can't be used directly, the window needs to be clicked first
           self.choiceB = master.bind('l', self.showResultEx2) #can't be used directly.


       def showResultEx1(self):
            #some codes
       def showResultEx2(self):
            #some codes

感谢您的帮助!

1 个答案:

答案 0 :(得分:1)

这是键盘焦点问题。我在绑定键盘之前添加Inductive type : Type := | TBool : type. Inductive term1 : Type := | tvar1 : term1. Inductive term2 : Type := | tvar2 : term2. Definition context := nat -> (option type). Class VDash (A B C : Type) := vdash : A -> B -> C -> Prop. Notation "G '⊢' t '::' T" := (vdash G t T) (at level 40, t at level 59). Inductive typing1 : VDash context term1 type := | T_Var1 : forall G T, G ⊢ tvar1 :: T with typing2 : VDash context term2 type := | T_Var2 : forall G T, G ⊢ tvar2 :: T. ,它解决了问题。