键盘不能直接在顶层使用python

keyboard can't be used directily in Toplevel python

我正在使用 Toplevel 生成两个 windows。但是当它打开第二个window时,键盘并没有立即激活(两个windows同时打开),我需要先点击第二个window才能使用键盘。我尝试使用 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

感谢您的帮助!

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