本人这段时间在自学编程
现在想用tkinter自制一个登录系统(用来练习),现在想要达成下面的功能
1.注册新用户之前,一定要先点击确认用户名按钮,如果不点击确认用户名字按钮的话,注册按钮无法点击或者即使点击注册按钮,也只是单纯的提示需要先点击确认用户名按钮,不会执行具体的注册功能
2.只有当新注册的用户名不存在与字典的情况下,点击注册按钮才能执行真正的注册功能
自己想了快半个月,试了好多种方法,也不知道如果实现需要的功能,不清楚思路
希望哪位可以帮帮忙,不胜感激
import tkinter as tk
class Login_interface():
def __init__(self):
self.dic1 = {'aaa':'123','bbb':'456'}
self.list1 = []
self.login_win = tk.Tk()
self.login_win.title('Login_OLNA_ERP')
self.login_win.geometry('450x300+500+200')
self.setUI()
self.login_win.mainloop()
def check_User_Name(self):
global entryNewUserName
global check_Name
for keys in self.dic1:
self.list1.append(keys)
if entryNewUserName.get() in self.list1:
print('ID已经被使用')
else:
print('ID可以使用,请输入密码')
print(self.dic1)
用来实现注册成功的功能
就是这里不知道怎么写,试过好多种if语句都是不行,不知道是什么思路
def success_User_Id(self):
global entryNewUserName
global entryNewUserPassword
self.dic1[entryNewUserName.get()] = entryNewUserPassword.get()
print(self.dic1)
def setUI(self):
# 账户ID
newUserName = tk.StringVar()
tk.Label(self.login_win, text='账号').place(x=50, y=60)
global entryNewUserName
entryNewUserName = tk.Entry(self.login_win, textvariable=newUserName)
entryNewUserName.place(x=150, y=60)
# 密码
newUserPassword = tk.StringVar()
tk.Label(self.login_win, text='密码').place(x=50, y=100)
global entryNewUserPassword
entryNewUserPassword = tk.Entry(self.login_win, show='*', textvariable=newUserPassword)
entryNewUserPassword.place(x=150, y=100)
# 按钮
buttonSingUp = tk.Button(self.login_win, text='注册', command=self.success_User_Id)
buttonSingUp.place(x=210, y=150)
buttonComfirmId = tk.Button(self.login_win, text='账户确认', command=self.check_User_Name)
buttonComfirmId.place(x=310, y=50)
if name=='main':
Login_interface()