0

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

谢谢你的帮助!

4

1 回答 1

1

这是键盘焦点问题。我focus_set()在绑定键盘之前添加,它解决了问题。

于 2017-05-18T20:47:23.227 回答