12.4每日总结
今天完成了人机交互
C/S结构用户界面设计
【实验编号】
10003809547j 图形用户界面设计
【实验学时】
8学时
【实验环境】
l 所需硬件环境为微机;
l 所需软件环境为Microsoft Visual Studio 2013
【实验内容】
编写一整套Mis系统UI界面,Mis系统名称自拟,尽量运用到如下控件:
l 窗体
l 菜单
l 工具栏
l 状态栏控件
l 标签控件
l 按钮控件
l 文本框控件
l 单选按钮控件
l 复选框控件
l 列表框控件
l 组合框控件
l 分组框控件
l 面板控件
l 图片框控件
l 定时器控件
l 滚动条控件
l 月历控件
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 | class StartPage: def __init__( self , parent_window, ImageTk = None ): parent_window.destroy() # 销毁子界面 self .window = tk.Tk() # 初始框的声明 self .window.title( '学生信息管理系统' ) self .window.geometry( '500x500' ) # 这里的乘是小x self .window.update_idletasks() # 更新窗口的大小和位置信息 screen_width = self .window.winfo_screenwidth() # 获取屏幕宽度 screen_height = self .window.winfo_screenheight() # 获取屏幕高度 window_width = self .window.winfo_width() # 获取窗口宽度 window_height = self .window.winfo_height() # 获取窗口高度 x = (screen_width - window_width) / / 2 # 计算窗口左上角 x 坐标 y = (screen_height - window_height) / / 2 # 计算窗口左上角 y 坐标 self .window.geometry( "+{}+{}" . format (x, y)) # 设置窗口位置 label = Label( self .window, text = "学生信息管理系统" , font = ( "Verdana" , 20 )) label.pack(pady = 100 ) # pady=100 界面的长度 Button( self .window, text = "管理员登陆" , font = tkFont.Font(size = 16 ), command = lambda : AdminPage( self .window), width = 30 , height = 2 , fg = 'white' , bg = 'gray' , activebackground = 'black' , activeforeground = 'white' ).pack() Button( self .window, text = "学生登陆" , font = tkFont.Font(size = 16 ), command = lambda : StudentPage( self .window), width = 30 , height = 2 , fg = 'white' , bg = 'gray' , activebackground = 'black' , activeforeground = 'white' ).pack() Button( self .window, text = "关于" , font = tkFont.Font(size = 16 ), command = lambda : AboutPage( self .window), width = 30 , height = 2 , fg = 'white' , bg = 'gray' , activebackground = 'black' , activeforeground = 'white' ).pack() Button( self .window, text = '退出系统' , height = 2 , font = tkFont.Font(size = 16 ), width = 30 , command = self .window.destroy, fg = 'white' , bg = 'gray' , activebackground = 'black' , activeforeground = 'white' ).pack() self .window.mainloop() # 主消息循环 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 | class AdminPage: def __init__( self , parent_window): parent_window.destroy() # 销毁主界面 self .window = tk.Tk() # 初始框的声明 self .window.title( '管理员登陆页面' ) self .window.geometry( '500x500' ) # 这里的乘是小x self .window.update_idletasks() # 更新窗口的大小和位置信息 screen_width = self .window.winfo_screenwidth() # 获取屏幕宽度 screen_height = self .window.winfo_screenheight() # 获取屏幕高度 window_width = self .window.winfo_width() # 获取窗口宽度 window_height = self .window.winfo_height() # 获取窗口高度 x = (screen_width - window_width) / / 2 # 计算窗口左上角 x 坐标 y = (screen_height - window_height) / / 2 # 计算窗口左上角 y 坐标 self .window.geometry( "+{}+{}" . format (x, y)) # 设置窗口位置 label = tk.Label( self .window, text = '管理员登陆' , bg = 'green' , font = ( 'Verdana' , 20 ), width = 30 , height = 2 ) label.pack() Label( self .window, text = '管理员账号:' , font = tkFont.Font(size = 14 )).pack(pady = 25 ) self .admin_username = tk.Entry( self .window, width = 30 , font = tkFont.Font(size = 14 ), bg = 'Ivory' ) self .admin_username.pack() Label( self .window, text = '管理员密码:' , font = tkFont.Font(size = 14 )).pack(pady = 25 ) self .admin_pass = tk.Entry( self .window, width = 30 , font = tkFont.Font(size = 14 ), bg = 'Ivory' , show = '*' ) self .admin_pass.pack() Button( self .window, text = "登陆" , width = 8 , font = tkFont.Font(size = 12 ), command = self .login).pack(pady = 40 ) Button( self .window, text = "返回首页" , width = 8 , font = tkFont.Font(size = 12 ), command = self .back).pack() self .window.protocol( "WM_DELETE_WINDOW" , self .back) # 捕捉右上角关闭点击 self .window.mainloop() # 进入消息循环 def login( self ): print ( str ( self .admin_username.get())) print ( str ( self .admin_pass.get())) admin_pass = None # 数据库操作 查询管理员表 db = pymysql.connect( host = 'localhost' , user = 'root' , password = '123456' , charset = 'utf8' , database = 'student' ) # 打开数据库连接 cursor = db.cursor() # 使用cursor()方法获取操作游标 sql = "SELECT * FROM admin_login_k WHERE admin_id = '%s'" % ( self .admin_username.get()) # SQL 查询语句 try : # 执行SQL语句 cursor.execute(sql) # 获取所有记录列表 results = cursor.fetchall() for row in results: admin_id = row[ 0 ] admin_pass = row[ 1 ] # 打印结果 print ( "admin_id=%s,admin_pass=%s" % (admin_id, admin_pass)) except : print ( "Error: unable to fecth data" ) messagebox.showinfo( '警告!' , '用户名或密码不正确!' ) db.close() # 关闭数据库连接 print ( "正在登陆管理员管理界面" ) print ( "self" , self .admin_pass) print ( "local" , admin_pass) if self .admin_pass.get() = = admin_pass: AdminManage( self .window) # 进入管理员操作界面 else : messagebox.showinfo( '警告!' , '用户名或密码不正确!' ) def back( self ): StartPage( self .window) # 显示主窗口 销毁本窗口 |
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY
· 【自荐】一款简洁、开源的在线白板工具 Drawnix