class LoginFrame(tk.Frame): def __init__(self, master=None): super().__init__(master) self.master = master self.master.title('登录系统') self.master.geometry('300x200') # 读取图片并创建 Label 组件 image = Image.open('C:/Users/hp/Desktop/orginalmodel/orginalmodel/pic1.jpg') image = image.resize((70,70)) photo = ImageTk.PhotoImage(image) self.image_label = tk.Label(self.master, image=photo) self.image_label.image = photo # 防止图片被垃圾回收器回收 self.image_label.pack() self.username_frame = tk.Frame(self.master) self.username_frame.pack() self.username_label = tk.Label(self.username_frame, text='用户名 ') self.username_label.pack(side=tk.LEFT) self.username_entry = tk.Entry(self.username_frame) self.username_entry.pack(side=tk.LEFT) self.password_frame = tk.Frame(self.master) self.password_frame.pack() self.password_label = tk.Label(self.password_frame, text=' 密码 ') self.password_label.pack(side=tk.LEFT) self.password_entry = tk.Entry(self.password_frame, show='*') self.password_entry.pack(side=tk.LEFT) self.login_button = tk.Button(self.master, text='登录', command=self.login) self.login_button.pack() def login(self): username = self.username_entry.get() password = self.password_entry.get() if username == 'AAA' and password == '111': self.master.destroy() root = tk.Tk() app = MainFrame(root) app.mainloop() else: tk.messagebox.showerror('错误', '用户名或密码错误!')修改代码,使pic1.jpg放在界面最底层
时间: 2023-07-14 19:11:53 浏览: 102
class LoginFrame(tk.Frame):
def __init__(self, master=None):
super().__init__(master)
self.master = master
self.master.title('登录系统')
self.master.geometry('300x200')
self.username_frame = tk.Frame(self.master)
self.username_frame.pack()
self.username_label = tk.Label(self.username_frame, text='用户名 ')
self.username_label.pack(side=tk.LEFT)
self.username_entry = tk.Entry(self.username_frame)
self.username_entry.pack(side=tk.LEFT)
self.password_frame = tk.Frame(self.master)
self.password_frame.pack()
self.password_label = tk.Label(self.password_frame, text=' 密码 ')
self.password_label.pack(side=tk.LEFT)
self.password_entry = tk.Entry(self.password_frame, show='*')
self.password_entry.pack(side=tk.LEFT)
self.login_button = tk.Button(self.master, text='登录', command=self.login)
self.login_button.pack()
# 读取图片并创建 Label 组件
image = Image.open('C:/Users/hp/Desktop/orginalmodel/orginalmodel/pic1.jpg')
image = image.resize((70,70))
photo = ImageTk.PhotoImage(image)
self.image_label = tk.Label(self.master, image=photo)
self.image_label.image = photo # 防止图片被垃圾回收器回收
self.image_label.pack(side=tk.BOTTOM) # 放在最底层
def login(self):
username = self.username_entry.get()
password = self.password_entry.get()
if username == 'AAA' and password == '111':
self.master.destroy()
root = tk.Tk()
app = MainFrame(root)
app.mainloop()
else:
tk.messagebox.showerror('错误', '用户名或密码错误!')
阅读全文