pythontkinter项目界面
python Tkinter版学生管理系统本文实例为大家分享了python tkinter版学生管理的具体代码,供大家参考,具体内容如下
tkinter是python自带的ui包,无需下载,只需要导入
tkinter 文档
//http://effbot.org/tkinterbook////
文档是英文版本的,可以翻译!
界面效果如下:
python的pc端界面还是可以的,较为美观!
页面较为粗狂,为经过专业设计!
系统的对象封装,数据连接使用的是原本控制台版本的!
控制台版本的系统,包含对象封装,数据连接
|
#导入tkinter 包 from tkinter import * from tkinter import ttk from com.hc.dao.connect import * from com.hc.entity.student import * root = tk() # 窗口宽高 英文x root.geometry( '600x500' ) # 固定窗口 root.resizable(width = false,height = false) # 窗口标题 root.title( 'hc king' ) # 标签 \ n label(root,text = '信息管理' ,bg = 'white' ,fg = 'red' ,font = ( '宋体' , 15 )).pack(side = top,fill = 'x' ) # 数据表格 #居中 datatreeview = ttk.treeview(root,show = 'headings' ,column = ( 'sid' , 'sname' , 'sex' , 'sage' )) datatreeview.column( 'sid' ,width = 150 ,anchor = "center" ) datatreeview.column( 'sname' ,width = 150 ,anchor = "center" ) datatreeview.column( 'sex' ,width = 150 ,anchor = "center" ) datatreeview.column( 'sage' ,width = 150 ,anchor = "center" ) datatreeview.heading( 'sid' ,text = '编号' ) datatreeview.heading( 'sname' ,text = '名称' ) datatreeview.heading( 'sex' ,text = '性别' ) datatreeview.heading( 'sage' ,text = '年龄' ) bottomframe = frame(root) sidlabel = label(leftframe,text = '编号:' ) snamelabel = label(leftframe,text = '名称:' ) sexlabel = label(leftframe,text = '性别:' ) sagelabel = label(leftframe,text = '年龄:' ) sidentry = entry(leftframe) snameentry = entry(leftframe) sexentry = entry(leftframe) sageentry = entry(leftframe) sidlabel.grid(row = 0 ,column = 0 ) sidentry.grid(row = 0 ,column = 1 ) snamelabel.grid(row = 0 ,column = 2 ) snameentry.grid(row = 0 ,column = 3 ) sexlabel.grid(row = 1 ,column = 0 ) sexentry.grid(row = 1 ,column = 1 ) sagelabel.grid(row = 1 ,column = 2 ) sageentry.grid(row = 1 ,column = 3 ) insbutton = button(rightframe,text = "添加" ,command = insert) insbutton.grid(row = 0 ,column = 0 ) delbutton = button(rightframe,text = "删除" ,command = delete) delbutton.grid(row = 0 ,column = 1 ) updbutton = button(rightframe,text = "修改" ,command = update) updbutton.grid(row = 1 ,column = 0 ) selbutton = button(rightframe,text = "查询" ,command = select) selbutton.grid(row = 1 ,column = 1 ) #定位式布局,即坐标 datatreeview.bind( '<<treeviewselect>>' ,treesel) #为datatreeview绑定事件 bottomframe.pack() #组件显示 root.mainloop() #界面运行 |
上述是系统的界面。
|
#点击datatreeview的某一项,就把数据拿到,放进四个输入框内 def treesel(event): item = datatreeview.selection() itemvalues = datatreeview.item(item, 'values' ) clearentry() sidentry.insert( 0 ,itemvalues[ 0 ]) snameentry.insert( 0 , itemvalues[ 1 ]) sexentry.insert( 0 , itemvalues[ 2 ]) sageentry.insert( 0 , itemvalues[ 3 ]) #把四个输入框的数据放进对象 def update(): student = student() student.stuid = sidentry.get() student.stuname = snameentry.get() student.stusex = sexentry.get() student.stuage = sageentry.get() database().upduser(student) clearandall() #删除datatreeview里面的数据 def clear(): clearentry() for item in datatreeview.get_children(): datatreeview.delete(item) def addall(): for o in database().alluser(): datatreeview.insert('', 0 , values = (o[ 0 ], o[ 1 ], o[ 2 ], o[ 3 ])) #清空四个输入框 def clearentry(): sidentry.delete( 0 , end) snameentry.delete( 0 , end) sexentry.delete( 0 , end) sageentry.delete( 0 , end) |
上述是系统所需的具体方法!
仍然需要改进!
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持开心学习网。
原文链接:https://blog.csdn.net/qq_43532342/article/details/83472013