如何检查回车键是否被按下python [英] how to check if the enter key is pressed python

查看:1660
本文介绍了如何检查回车键是否被按下python的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个绑定事件,当按下某个键触发功能时,我如何查看所按下的键是否为Enter键? 这是我的代码:

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:

这不起作用.我将用Enter替换单词以检查是否按下了回车键:

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")

推荐答案

您可以使用keyym进行检查:

You can check using keysym:

if event.keysym == 'Return'

这篇关于如何检查回车键是否被按下python的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆