Введите ключ Python Tkinter - PullRequest
       4

Введите ключ Python Tkinter

0 голосов
/ 05 декабря 2018

Привет, поэтому я хочу, чтобы моя программа «входила в систему» ​​всякий раз, когда я нажимал клавишу ввода.Как мне это сделать?

Мой код:

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)

Спасибо

1 Ответ

0 голосов
/ 05 декабря 2018

Вы можете связать ввод с функцией в tkinter:

from tkinter import *

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

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

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

window.mainloop()
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...