淘宝网怎样做网站,代还app开发公司,博物馆设计公司哪个好,中国十大原画培训机构下一篇#xff1a;
本项目将分段设计“图书管理登录UI界面”的用户登录、用户注册、用户账号找回等。主要围绕GUI标准库tkinter、以及类的继承#xff08;重点#xff09;来设计本项目。
首先新建一个文件夹命名为“图书管理系统项目”#xff0c;并在其目录下新建文件夹…下一篇
本项目将分段设计“图书管理登录UI界面”的用户登录、用户注册、用户账号找回等。主要围绕GUI标准库tkinter、以及类的继承重点来设计本项目。
首先新建一个文件夹命名为“图书管理系统项目”并在其目录下新建文件夹code、photo、user_data。然后在code目录下新建“登录UI.py”再然后把图片放在photo目录下如下图 注意此时的窗口组件并未绑定触发事件所以按键无法触发。 运行结果 登录UI.py 代码示例
登录UI 模块
# 通配符 *
__all__ [LoginUI]import tkinter as tk
from tkinter import ttkclass LoginUI(tk.Tk):继承tk.Tk创建登录UIdef __init__(self):构造方法# 调用tk.Tk的构造方法super().__init__()self.width self.winfo_screenwidth() # 窗口宽初始位置为屏幕宽度位置显示self.height self.winfo_screenheight() # 窗口高初始位置为屏幕高度位置显示# 设计自己项目的UIself.title(图书管理登录界面) # 标题self.geometry(f610x406{self.width//4}{self.height//8}) # 窗口像素大小self.resizable(0, 0) # 窗口大小禁止调节# 窗口背景图self.backgroundPhoto tk.PhotoImage(file..\\photo\\用户登录背景.png)self.backgroundButton ttk.Button(self, imageself.backgroundPhoto)self.backgroundButton.pack()# 系统名self.titleLabel tk.Label(self, text图 书 管 理 系 统, font(Tahoma, 30, bold))self.titleLabel.place(x118, y40)# 输入格式错误提示self.hintLabel tk.Label(self, text欢迎使用【图书管理系统】)self.hintLabel.pack(sidetk.BOTTOM, filltk.BOTH)# 用户名tk.Label(self, text用户名).place(x170, y160)# 输入用户名self.userName tk.StringVar()self.userEntry ttk.Entry(self, textvariableself.userName, width22)self.userEntry.place(x223, y161)# 随机用户名self.randomPhoto tk.PhotoImage(file..\\photo\\随机用户名.png)self.randomButton tk.Button(self, imageself.randomPhoto, relieftk.FLAT)self.randomButton.place(x358, y162)# 密码tk.Label(self, text密 码).place(x170, y200)# 输入密码self.password tk.StringVar()self.passwordEntry ttk.Entry(self, textvariableself.password, width22)self.passwordEntry.place(x223, y201)# 显示/隐藏密码self.showOrConcealCount 0self.showPhoto tk.PhotoImage(file..\\photo\\密码显示.png)self.concealPhoto tk.PhotoImage(file..\\photo\\密码隐藏.png)self.showOrConcealButton tk.Button(self, imageself.showPhoto, relieftk.FLAT)self.showOrConcealButton.place(x358, y205)# 验证码tk.Label(self, text验证码).place(x170, y244)# 输入验证码self.inputVerifyCode tk.StringVar()self.verifyEntry ttk.Entry(self, textvariableself.inputVerifyCode, width15)self.verifyEntry.place(x223, y244)# 随机验证码self.showVerifyCode tk.StringVar(value获取验证码)self.verifyButton tk.Button(self, textvariableself.showVerifyCode, reliefflat, width8)self.verifyButton.place(x350, y240)# 刷新验证码self.updatePhoto tk.PhotoImage(file..\\photo\\验证码更新.png)self.updateButton tk.Button(self, imageself.updatePhoto, reliefflat)self.updateButton.place(x310, y245)# 注册self.registerButton ttk.Button(self, text注册, width4)self.registerButton.place(x395, y159)# 找回self.retrieveButton ttk.Button(self, text找回, width4)self.retrieveButton.place(x395, y199)# 登录self.loginButton ttk.Button(self, text登录)self.loginButton.place(x200, y300)# 退出ttk.Button(self, text退出, commandself.destroy).place(x310, y300)# 代码测试
if __name__ __main__:ui LoginUI() # 对象实例化ui.mainloop() # 窗口主循环
else:print(f导入【{__name__}】模块) 作者周华
传作日期2023/12/10