本文实例为大家分享了python tkinter版学生管理的具体代码,供大家参考,具体内容如下
tkinter是python自带的ui包,无需下载,只需要导入
tkinter 文档
//http://effbot.org/tkinterbook////
文档是英文版本的,可以翻译!
界面效果如下:
python的pc端界面还是可以的,较为美观!
页面较为粗狂,为经过专业设计!
系统的对象封装,数据连接使用的是原本控制台版本的!
控制台版本的系统,包含对象封装,数据连接
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
|
#导入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() #界面运行
|
上述是系统的界面。
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
|
#点击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