Python Tk 制作用户登陆窗口

废话不多说,直接上代码

from tkinter import Tk, Label, Entry, Button, messagebox

root = Tk()

username = "admin"
password = 12345678


def check():
    global username, password
    input_value = entry.get()
    input_value_1 = entry_1.get()
    if input_value == username and input_value_1 == password:
        messagebox.showinfo(title=f"Landing results", message=f"Verified passed")
    else:
        messagebox.showwarning(title=f"Landing results", message=f"Wrong username or password")


def sign_in():
    global root, username, password
    Label(root, text="username:").pack()

    entry_2 = Entry(root, show="")
    entry_2.pack()

    Label(root, text="password:").pack()

    entry_3 = Entry(root, show="•")
    entry_3.pack()

    Label(root, text="Confirm your password:").pack()

    entry_4 = Entry(root, show="•")
    entry_4.pack()

    def confirm_password():
        global username, password
        if entry_3.get() == entry_4.get() and len(entry_3.get()) >= 8 and entry_3.get() == int:
            username = entry_2.get()
            password = entry_3.get()
            messagebox.showinfo(title=f"Registration result", message=f"Registration is successful")
        else:
            messagebox.showwarning(title=f"Registration result",
                                   message=f"The password is inconsistent or the password length is less than eight")

    Button(root, text="sign_in", command=confirm_password).pack()


def esc():
    exit()


root.title("log in")

Label(root, text="Please enter a username:").pack()

entry = Entry(root, show="")
entry.pack()

Label(root, text="Please enter a password:").pack()

entry_1 = Entry(root, show="")
entry_1.pack()

Button(root, text="log in", command=check).pack()

label = Label(root, text="")
label.pack()

Button(root, text="sign in", command=sign_in).pack()
Button(root, text="exit", command=esc).pack()
root.mainloop()

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值