how to check if the enter key is pressed python

烂漫一生 提交于 2019-12-13 17:41:04

问题


I have a bind event for when a key is pressed to trigger a function but how would I see if the key pressed was the enter key? Here is my code:

This did not work. What would I replace the word enter with to check if the enter key is pressed:

def record(self,event):
    x = event.char
    if x == "Enter":
        print("Enter")

回答1:


You can check using keysym:

if event.keysym == 'Return'


来源:https://stackoverflow.com/questions/24671105/how-to-check-if-the-enter-key-is-pressed-python

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!