新建文件,运行界面要求如下: 1假定用户名为“admin”,密码为“123456”,如果用户名和密码正确,显示如下界面。2如果用户名或密码不正确,显示如下界面。3单击“重填”按钮,清空两个输入框

思路:…模仿的,以后再加上去

from tkinter import *
from tkinter import messagebox as msgbox

root = Tk()
root.minsize(300, 200)
root.title("登陆窗口")


def login():
    if s1.get() == "admin" and s2.get() == "123456":
        msgbox.showinfo("恭喜", " 登录成功")
    else:
        msgbox.showerror("警告", "用户名或密码错误")
        s1.set("")
        s2.set("")


def re():
    s1.set("")
    s2.set("")


Label(root, text="输入用户名:").place(x=50, y=40)
Label(root, text="  输入密码:").place(x=54, y=70)
s1 = StringVar()
s2 = StringVar()
Entry(root, textvariable=s1, width=14).place(x=120, y=40)
Entry(root, textvariable=s2, width=14, show="*").place(x=120, y=70)
Button1 = Button(root, text="登录", width=5, command=login).place(x=80, y=120)
Button2 = Button(root, text="重填", width=5,command=re).place(x=140, y=120)
mainloop()

版权声明:本文为winds_tide原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。