开发者

Python/Tkinter: How can I get the .bind() method to work with keyboard keys?

I'm trying to learn Tkinter but I'm running into a problem. I'd like it so once the user hits their Enter key it will copy what is in an Entry field. I was planning on using the .bind() method but it doesn't seem to register my key press开发者_StackOverflowes. I tried multiple ways and it seems if they are keyboard related, they do not work.

self.frame.bind("<Return>", self.testevent)   #Doesn't Work
self.frame.bind("<Enter>", self.testevent)    #Works
self.frame.bind("<Button-1>", self.testevent) #Works
self.frame.bind("<F1>", self.testevent)       #Doesn't work

There are no errors that pop up when the script is compiled. I've looked around and have been unable to find an answer.

Edit: One of my sentences was jumbled.


It seems you have to call self.frame.focus_set() first.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜