在python中使用tkinter创建一个“新用户”弹出窗口

时间:2018-11-03 20:47:32

标签: python tkinter messagebox

我正在尝试创建一个应用程序,单击链接后您会打开一个弹出窗口,可以在其中创建该应用程序的新用户。这要求输入用户ID,密码和确认密码。如果密码和确认密码不匹配,则会显示一个消息框,提示密码不匹配,但是当密码实际匹配时,它会再次显示相同的消息。有人可以帮忙解决这个问题吗?

def new_user_function(*args):
    if password == confirm_pass:
        MyDB.add_new_user(email, password)
    else:
        messagebox.showinfo("Passwords don't match")

def new_user_function_popup(*args):
    """This will open a pop up window for adding new users"""
    user_popup = Toplevel()
    user_popup.title("Create New user")

    ttk.Label(user_popup, text = "Enter Email ID").grid(column = 0, row = 0, sticky = E)
    ttk.Label(user_popup, text = "New Password").grid(column = 0, row = 1, sticky = E)
    ttk.Label(user_popup, text = "Confirm Password").grid(column = 0, row = 2, sticky = E)

    ttk.Entry(user_popup, width = 25, textvariable = user_id).grid(column = 1, row = 0, sticky = (E,W))
    ttk.Entry(user_popup, width = 25, textvariable = password, show = "*").grid(column = 1, row = 1, sticky = (E,W))
    ttk.Entry(user_popup, width = 25, textvariable = confirm_pass, show = "*").grid(column = 1, row = 2, sticky = (E,W))

    ttk.Button(user_popup, text = 'Create', command = new_user_function).grid(column = 1, row = 3, sticky = (E,W))  

user_id = StringVar()
password = StringVar()
confirm_pass = StringVar()
upload_fp = StringVar()
save_fp = StringVar()

1 个答案:

答案 0 :(得分:0)

正如stovfl所正确指出的那样,解决方案是使用get()函数。 StringVar()是一个创建python对象的类,但是要获取值,我们需要使用该类中定义的方法,get()会这样做。