import tkinter
from tkinter import *
class manager:
def __init__(self):
self.Window = tkinter.Tk()
self.Window.geometry("200x200+50+50") # heightxwidth+x+y
self.mainpanel = Canvas(self.Window, width=200, height=200) # main screen
self.mainpanel.pack()
entry_text = StringVar() # the text in your entry
entry_widget = Entry(self.mainpanel, width=20, textvariable=entry_text) # the entry
self.mainpanel.create_window(100, 100, window=entry_widget)
def test(content):
if content.isalnum() or content == "":
return True
else:
return False
lable1 = Label(self.Window, text="账号:", )
lable1.place(x=10, y=30)
v = StringVar()
test_cmd = self.Window.register(test)
textEntry1 = Entry(self.Window, bd=0, font=12, relief=RIDGE, bg="lightcyan",
textvariable=v,
validate="key",
validatecommand=(test_cmd, '%P')
)
textEntry1.place(x=45, y=30, width=130, height=25)
self.Window.mainloop()
if __name__ == '__main__':
app = manager()
isalnum() 包括 A--Z a--z 0--9. 也包括中文字
只有符號會 False.
可以使用
if content.isascii() and content.isalnum() :
return True
elif content == "" :
return True
else:
return False
你把报错信息发给我看一下