from tkinter import *
from tkinter import messagebox
class Application(Frame):
def __init__(self, master=None):
super().__init__(master)
self.master = master
self.pack()
self.creatWidget()
def creatWidget(self):
Label(self, text="用户名").pack()
# 用户名
var_user_name = StringVar()
self.entry_user_name = Entry(self, textvariable=var_user_name)
self.entry_user_name.pack()
var_user_name.set("admin")
Label(self, text="密码").pack()
# 密码
var_user_pwd = StringVar()
self.entry_user_pwd = Entry(self, textvariable=var_user_pwd, show="*")
self.entry_user_pwd.pack()
btn1 = Button(self, text="登陆", command=self.songhua)
btn1.pack()
def songhua(self):
username = self.entry_user_name.get()
pwd = self.entry_user_pwd.get()
print("用户名:", username)
print("密码:", pwd)
if username == "jiangjun" and pwd == "123456":
messagebox.showinfo(" ", "登陆成功,欢迎使用")
else:
messagebox.showinfo(" ", "登陆失败,请重新输入")
windows = Tk()
windows.geometry(“400x300+800+300”)
windows.title(“一个经典的GUI”)
app = Application(master=windows)
windows.mainloop()