import tkinter as tk import tkinter.messagebox from 主页面 import MainPage #from 家居信息 import JiaJuPage class LoginPage: def __init__(self,master): self.root = master self.page = tk.Frame(self.root) self.page.pack() self.root.title('智能家居系统') self.root.geometry("300x180") self.username = tk.StringVar() self.password = tk.StringVar() tk.Label(self.page).grid(row=0, column=0) tk.Label(self.page, text='账户').grid(row=1,column=0) tk.Entry(self.page, textvariable=self.username).grid(row=1, column=1) tk.Label(self.page, text='密码').grid(row=2, column=0) tk.Entry(self.page, textvariable=self.password).grid(row=2, column=1, pady=10) tk.Button(self.page, text='登录', command=self.login_check).grid(row=3, column=0, pady=10) tk.Button(self.page, text='退出', command=root.quit).grid(row=3, column=1, pady=10,stick=tk.E) def login_check(self): name = self.username.get() pwd = self.password.get() if name == '123' or pwd == '123' : tkinter.messagebox.showinfo(title='恭喜', message='登录成功') self.page.destroy() #JiaJuPage(self.root) MainPage(self.root) else: tkinter.messagebox.showinfo(title='错误', message='账户或密码错误') if __name__ == '__main__': root = tk.Tk() root.title("智能家居系统") LoginPage(root) root.mainloop()