colinni11 2022-02-10 21:32 采纳率: 100%
浏览 23
已结题

PYTHON 注册用户前 一定要先点击确认Button的逻辑

本人这段时间在自学编程
现在想用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()

  • 写回答

1条回答 默认 最新

  • 小康2022 Python领域新星创作者 2022-02-10 22:56
    关注

    不知道我的注释与修改你能否看懂,我的能力有限,只能改成这样
    关于Button控件、Label控件等的Tkinter模块知识,你可以看看我的博客,那里面有完整参数:
    https://blog.csdn.net/weixin_62651706/article/details/122832367?spm=1001.2014.3001.5501
    【有帮助请采纳】

    import tkinter as tk
    
    class Login_interface():
        def __init__(self):
     
            self.dic1 = {'aaa':'123','bbb':'456'}
            self.list1 = []
    
            self.isOK = 0 #【定义一个变量来存储是否点击按钮“账户确认”的信息,0为没有点击,1为已点击】
     
            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
    
            self.isOK = 1#【点击了“账户确认”,设置该变量为1】
            self.buttonSingUp.config(state='normal')#【并更改“注册”按钮的状态为正常】
    
            for keys in self.dic1:
                self.list1.append(keys)
     
            if entryNewUserName.get() in self.list1:
                print('ID已经被使用')
            else:
                print('ID可以使用,请输入密码')
     
            print(self.dic1)
    
        def success_User_Id(self):
    
            global entryNewUserName
            global entryNewUserPassword
     
            if entryNewUserName.get() != '' and entryNewUserName.get() not in self.dic1.keys():#【加一个简单的'if'语句,'self.dic1.keys()'是该字典的键值列表,顺便判断一下用户名是否为空】
                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)
     
            # 按钮
            self.buttonSingUp = tk.Button(self.login_win, text='注册', command=self.success_User_Id, state='disabled')#【设置该按钮的初始状态为禁用】
            self.buttonSingUp.place(x=210, y=150)#【注意:为了方便,我在'buttonSingUp'前面加了一个'self.'】
     
            buttonComfirmId = tk.Button(self.login_win, text='账户确认', command=self.check_User_Name)
            buttonComfirmId.place(x=310, y=50)
    
    Login_interface()#【这行代码是我加上去的】
    #【下面这个是我的登录注册界面,你看看效果,需要源码就私信我】
    

    【有帮助请采纳】

    img

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

问题事件

  • 系统已结题 2月20日
  • 已采纳回答 2月12日
  • 创建了问题 2月10日

悬赏问题

  • ¥15 win10权限管理,限制普通用户使用删除功能
  • ¥15 minnio内存占用过大,内存没被回收(Windows环境)
  • ¥65 抖音咸鱼付款链接转码支付宝
  • ¥15 ubuntu22.04上安装ursim-3.15.8.106339遇到的问题
  • ¥15 求螺旋焊缝的图像处理
  • ¥15 blast算法(相关搜索:数据库)
  • ¥15 请问有人会紧聚焦相关的matlab知识嘛?
  • ¥15 网络通信安全解决方案
  • ¥50 yalmip+Gurobi
  • ¥20 win10修改放大文本以及缩放与布局后蓝屏无法正常进入桌面