tkinter Label的textvariable参数问题
本帖最后由 qin_yin 于 2020-11-29 01:23 编辑import tkinter as tk
class Login:
def __init__(self, master):
'''登录界面初始化'''
def login_method():
pass
def sign_up_window():
'''注册窗口的一系列反馈'''
sign_up = tk.Tk()
sign_up.geometry('600x200')
sign_up.title('sign up')
label = tk.Label(master=sign_up,text='Urse name\n\npass word\n\nConfirm password',
font=('华康少女字体', 14), justify='left')
label.place(x=10, y=10)
urse_name = tk.Entry(master=sign_up)
urse_name.place(x=200, y=15)
password = tk.Entry(master=sign_up, show='*')
password.place(x=200, y=50)
confirm_password = tk.Entry(master=sign_up,show='*')
confirm_password.place(x=200,y=90)
def dete(): ##为什么这里Label没有显示内容?我测试一下的条件已经成立了啊{:10_266:}
tips_name = tk.StringVar()
tips_name.set('123213213')
tips_password = tk.StringVar()
tips_password.set('123')
tips_confrm_ps = tk.StringVar()
tips_confrm_ps,set('213')
'''判断用户输入是否合法,给予相对提示'''
if urse_name.get() == '':
print(1)
tips_name.set('用户名不能为空')
tk.Label(master=sign_up, textvariable=tips_name.get()).place(x=400, y=10)
if password.get() == '':
print(2)
tips_password.set('密码不能为空')
tk.Label(master=sign_up, textvariable=tips_password.get()).place(x=400, y=30)
elif password.get() != confirm_password.get():
print(3)
tips_confrm_ps.set('两次输入不一致')
tk.Label(master=sign_up, textvariable=tips_confrm_ps.get()).place(x=400, y=50)
def call_off():
pass
ok = tk.Button(master=sign_up, text='OK', command=dete, width=7, height=2).place(x=240, y=130)
cancle = tk.Button(master=sign_up, text='cancle', command=call_off, width=7, height=2).place(x=100, y=130)
sign_up.mainloop()
self.window = master
self.window.title('Login')
self.window.geometry('500x300')
self.image_file = tk.PhotoImage(file='C:\\Users\\Admin\\Desktop\\图.png')
self.image_label = tk.Label(self.window, image=self.image_file)
self.image_label.place(x=70, y=15)
self.urse_account = tk.Label(self.window, text='account', font=('华康少女字体', 20), fg='green')
self.urse_account.place(x=70, y=150)
self.password = tk.Label(self.window, text='Password', font=('华康少女字体', 20), fg='green')
self.password.place(x=70, y=180)
self.account_entry = tk.Entry(self.window, width=25, font=('华康少女字体', 15))
self.account_entry.place(x=200, y=160)
self.password_entry = tk.Entry(self.window, width=25, font=('华康少女字体', 15), show='*')
self.password_entry.place(x=200, y=187)
self.login_button = tk.Button(self.window, text='Login',width=10, height=2, command=login_method)
self.login_button.place(x=130,y=220)
self.sign_up_button = tk.Button(self.window, text='sign up', width=10, height=2, command=sign_up_window)
self.sign_up_button.place(x=280, y=220)
self.window.mainloop()
if __name__ == '__main__':
root = tk.Tk()
login = Login(root)
textvariable 填写的是变量名,不用 get
参考代码:
tips_name.set('用户名不能为空')
tk.Label(master=sign_up, textvariable=tips_name).place(x=400, y=10)
Twilight6 发表于 2020-11-29 09:04
textvariable 填写的是变量名,不用 get
参考代码:
我把get取消了,依然没有显示 qin_yin 发表于 2020-11-29 20:42
我把get取消了,依然没有显示
程序中只能有一个根窗口
把 sign_up = tk.Tk() 改成 sign_up = tk.Toplevel()
然后把sign_up.mainloop() 删了
Twilight6 发表于 2020-11-29 21:52
程序中只能有一个根窗口
把 sign_up = tk.Tk() 改成 sign_up = tk.Toplevel()
Tk()和Toplevel()有什么区别
页:
[1]