gpt4 book ai didi

python - 输入 Python Tkinter key

转载 作者:行者123 更新时间:2023-12-01 01:22:57 25 4
gpt4 key购买 nike

嗨,基本上我希望我的程序在我按下回车键时“登录”。我该怎么做?

我的代码:

def Login(event=None):
Db() #calls the database function/ subroutine
if USERNAME.get() == "" or PASSWORD.get() == "":
lbl_text.config(text="Please fill in the required details", fg="red", font="Arial")
PASSWORD.set("") #resets the password field to nill (with no username the password field is useless)
else:
cursor.execute("SELECT * FROM `member` WHERE `username` = ? AND `password` = ?", (USERNAME.get(), PASSWORD.get())) #username and password retrieved from database
if cursor.fetchone() is not None:
Home()
PASSWORD.set("") #resets password field to nill, so nobody can log in with same credentials if the log in window is left open
lbl_text.config(text="")
else:
lbl_text.config(text="Incorrect Details entered", fg="red", font="Arial")
PASSWORD.set("") #resets the password field to nill (I don't do the same with the password field, as the password field is typically wrong)
cursor.close()
conn.close()

btn_login = Button(Form, text="Login", width=45, command=Login)
btn_login.grid(pady=25, row=3, columnspan=3)
btn_login.bind('<Return>', Login)

谢谢

最佳答案

您可以将 Enter 绑定(bind)到 tkinter 中的函数:

from tkinter import *

window = Tk()
window.geometry("600x400")
window.title("Test")

def test(event):
print("Hi")

window.bind("<Return>", test)

window.mainloop()

关于python - 输入 Python Tkinter key ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53633233/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com