蒟蒻求助tkinter
  • 板块灌水区
  • 楼主New_hope
  • 当前回复4
  • 已保存回复4
  • 发布时间2022/2/27 17:05
  • 上次更新2023/10/28 07:35:37
查看原帖
蒟蒻求助tkinter
416242
New_hope楼主2022/2/27 17:05
import tkinter as tk
import tkinter.messagebox

window = tk.Tk()
window.title('Charity Sale Login System')
window.geometry('450x300')

#login and sign up button

def user_login():
    
    x = entry_user_name.get()
    y = entry_user_pwd.get()
    print('usernamenow',x,'username',user_name)
    if user_name == '':
        yes_or_no = tk.messagebox.askyesno(title='Wrong',message='It seems that you have not sign up.Sign up today?')
        if yes_or_no:
            user_sign_up()
    elif y != user_password:
        tk.messagebox.showinfo(title='Wrong',message='It seems that you inputed a wrong password')
    elif x == user_name and y == user_password:
        tk.messagebox.showinfo(title='Congratulations',message='You log in successfully.Enjoy yourself!')

def user_sign_up():
    window_sign_up = tk.Toplevel(window)
    window_sign_up.title('Sign up Window')
    window_sign_up.geometry('350x275')

    def apply():
        
        user_nname = var_new_name.get()
        user_new_pwd = var_new_pwd.get()
        user_confirm_pwd = var_confirm_pwd.get()
        
        print('username:',user_nname,'password:',user_new_pwd,'confirm password:',user_confirm_pwd,sep=' ')
        
        if user_new_pwd != user_confirm_pwd:
            decision = tk.messagebox.askyesno(title='Wrong',message='You probably forget the password.Try it again?')
            if decision:
                var_new_pwd.set('')
                var_confirm_pwd.set('')
            else:
                window_sign_up.destroy()
        elif user_nname == 'example@Python.com':
            decision = tk.messagebox.askyesno(title='Wrong',message='That one cannot be used.Try another good name?')
            if decision:
                var_new_name.set('')
                var_new_pwd.set('')
                var_confirm_pwd.set('')
            else:
                window_sign_up.destroy()
        else:
            user_name = user_nname
            user_password = user_new_pwd
            tk.messagebox.showinfo(title='Congratulations',message='You sign up successfully.You only need to log again')
            window_sign_up.destroy()
            
    var_new_name=tk.StringVar()
    var_new_name.set('example@Python.com')
    var_new_pwd=tk.StringVar()
    var_confirm_pwd=tk.StringVar()

    tk.Label(window_sign_up,text='New User Name:').place(x=7,y=40)
    entry_new_name = tk.Entry(window_sign_up,textvariable=var_new_name).place(x=120,y=40)
    
    tk.Label(window_sign_up,text='New Password:').place(x=7,y=80)
    entry_new_pwd = tk.Entry(window_sign_up,textvariable=var_new_pwd,show='*').place(x=110,y=80)
    
    tk.Label(window_sign_up,text='Confirm Password:').place(x=7,y=120)
    entry_confirm_pwd = tk.Entry(window_sign_up,textvariable=var_confirm_pwd,show='*').place(x=130,y=120)
    
    button_sure = tk.Button(window_sign_up,text='Make it',command=apply).place(x=130,y=180)
    
#标题
l = tk.Label(window,text='Charity Sale Login System',bg='Red',font=('Arial',12),
             width=30,height=2)
l.pack()
#User info
user_name=''
user_password=''
    
var_user_name=tk.StringVar()
var_user_name.set('example@python.com')
var_user_pwd=tk.StringVar()

tk.Label(window,text='User Name:').place(x=50,y=150)
tk.Label(window,text='Password:').place(x=50,y=190)

entry_user_name = tk.Entry(window,textvariable=var_user_name)
entry_user_name.place(x=160,y=150)

entry_user_pwd = tk.Entry(window,textvariable=var_user_pwd,show='*')
entry_user_pwd.place(x=160,y=190)

but_login = tk.Button(window,text='Login',command=user_login).place(x=170,y=230)
but_sign_up = tk.Button(window,text='Sign up',command=user_sign_up).place(x=270,y=230)    


window.mainloop()


学校老师要求的作业,tkinter可以说是现学现用,刚开始浅学Python

不知道为什么sign up之后user_name没有更新,一直是空格,有些调试代码~~(我只会print调试)~~已经写好,十分感谢!!!

2022/2/27 17:05
加载中...