當我試圖進入的東西,它只是將無效塊,沒有讓我輸入密鑰。我明白了,我可以通過使用其他選項「焦點」擺脫它,「事件的內容」等,但我想它與主要工作:輸入驗證與Tkinter的
from tkinter import *
import re
def validate_email(P):
# master.errormsg.config(text='')
x = re.match(r"[^@][email protected][^@]+\.[^@]+", P)
print(P)
errormsg.config(text='')
emailentry.focus_set()
return x != None
def invalid_email(P):
errormsg.config(text='Invalid Email Address')
emailentry.focus_set()
if __name__ == '__main__':
master = Tk()
errormsg = Label(master,text='', fg='red')
errormsg.pack()
L1 = Label(master, text='Enter Email Address')
L1.pack(side=LEFT)
vcmd = (master.register(validate_email), '%P')
invcmd = (master.register(invalid_email), '%P')
emailentry = Entry(master, validate="focusout", validatecommand=vcmd,
invalidcommand=invcmd)
emailentry.pack()
Button(master, text="Login").pack()
master.mainloop()
哎呀!與驗證=鍵改變代碼....我指的「鑰匙」 –