gpt4 book ai didi

使用python实现名片管理系统

转载 作者:qq735679552 更新时间:2022-09-29 22:32:09 25 4
gpt4 key购买 nike

CFSDN坚持开源创造价值,我们致力于搭建一个资源共享平台,让每一个IT人在这里找到属于你的精彩世界.

这篇CFSDN的博客文章使用python实现名片管理系统由作者收集整理,如果你对这篇文章有兴趣,记得点赞哟.

python实现名片管理系统(界面+数据库) 。

开发一个简单的信息管理系统(类似于前面的名片管理系统),要求:

1.用结构化方法或面向对象开发方法开发系统 2.有图形用户界面 3.用数据库存储数据 4.用python语言实现系统 。

部分功能如下图 。

进入时的界面 。

使用python实现名片管理系统

显示所有名片后的界面 。

使用python实现名片管理系统

新建名片功能 。

使用python实现名片管理系统

新建成功 。

使用python实现名片管理系统

查找名片里包含(修改名片和删除名片) 。

使用python实现名片管理系统

具体代码如下 。

?
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
import sys
from tkinter import *
from tkinter.messagebox import *
from tkinter import ttk
import sqlite3
 
con = sqlite3.connect(r "D:\Python练习\作业\12月6日python\card.db" )
#con.execute("create table card(name primary key ,phone,QQ,email)")
 
#新增名片
def add():
  add = Tk()
  add.geometry( '260x140+350+200' )
  add.minsize( 260 , 140 )
  add.maxsize( 260 , 140 )
  add.title( "新建名片" )
  lf = LabelFrame(add,text = "请 输 入 :" ,labelanchor = N)
  lf.pack()
  Label(lf, text = "姓 名:" ).grid(row = 0 ,column = 0 )
  Label(lf, text = "电 话:" ).grid(row = 1 ,column = 0 )
  Label(lf, text = "Q Q:" ).grid(row = 2 , column = 0 )
  Label(lf, text = "Email:" ).grid(row = 3 , column = 0 )
  name = Entry(lf)
  name.grid(row = 0 ,column = 1 ,columnspan = 2 )
  phone = Entry(lf)
  phone.grid(row = 1 ,column = 1 ,columnspan = 2 )
  qq = Entry(lf)
  qq.grid(row = 2 ,column = 1 ,columnspan = 2 )
  email = Entry(lf)
  email.grid(row = 3 ,column = 1 ,columnspan = 2 )
  #确定按钮添加数据
  def qd_event():
  try :
  if name.get() = = "":
  showinfo(title = "提示" , message = "姓名不能为空!" )
  add.destroy()
  else :
  con = sqlite3.connect(r "D:\Python练习\作业\12月6日python\card.db" )
  cardList = (name.get(),phone.get(),qq.get(),email.get())
  con.execute( "insert into card(name,phone,QQ,email) values (?,?,?,?)" ,cardList)
  #card = {"姓名":name.get(),"电话":phone.get(),"QQ":qq.get(),"Email":email.get()}
  #card_list.append(card)
  con.commit()
  con.close()
  add.destroy()
  show_all()
  #save_data()
  showinfo(title = "提示" , message = "新建名片成功!" )
  except :
  print ( "error occur" )
  showinfo(title = "警告" , message = "姓名不能重复!" )
  #取消按钮
  def qx_event():
  add.destroy()
  Button(lf,text = " 确 定 " ,command = qd_event).grid(row = 4 ,column = 2 ,sticky = W)
  Button(lf,text = " 取 消 " ,command = qx_event).grid(row = 4 ,column = 1 ,sticky = E)
 
#显示所有
def show_all():
  x = dataTreeview.get_children()
  for item in x:
  dataTreeview.delete(item)
  con = sqlite3.connect(r "D:\Python练习\作业\12月6日python\card.db" )
  cur = con.execute( "select * from card" )
  for i in cur:
  print (i)
  n = 0
  #dataTreeview.insert('', 1, values=("1","2","3","4"))
  dataTreeview.insert('',n, values = i)
  n + = 1
 
#清空数据
def del_all():
  x = dataTreeview.get_children()
  for item in x:
  dataTreeview.delete(item)
 
#查询名片
def search_card():
  search = Tk()
  search.geometry( '240x50+450+300' )
  search.minsize( 240 , 80 )
  search.maxsize( 400 , 170 )
  search.title( "查找名片" )
  lf = LabelFrame(search, text = "请 输 入 :" , labelanchor = N)
  lf.pack()
  Label(lf, text = "姓 名:" ).grid(row = 0 , column = 0 )
  name = Entry(lf)
  name.grid(row = 0 , column = 1 , columnspan = 2 )
  #print(name.get())
  def sure():
  con = sqlite3.connect(r "D:\Python练习\作业\12月6日python\card.db" )
  cur = con.execute( "select * from card" )
  for i in cur:
  #print(i)
  #print(name.get())
  #print(name.get()==i[0])
  if name.get() = = i[ 0 ]:
  print ( "查找成功" )
  #print(i[0])
  update(i[ 0 ])
 
  search.destroy()
  break
  else :
  showinfo(title = "提示" ,message = "没有找到!" )
  Button(lf, text = "查找" , command = sure).grid(row = 1 , column = 1 , sticky = N)
 
#修改名片
def update(n):
 
  update = Tk()
  update.geometry( '400x170+350+200' )
  update.minsize( 400 , 170 )
  update.maxsize( 400 , 170 )
  update.title( "查找名片" )
  lf1 = LabelFrame(update, text = "名片信息" ,labelanchor = N)
  lf1.pack()
  Label(lf1, text = "姓 名:" ).grid(row = 0 , column = 0 )
  Label(lf1, text = "电 话:" ).grid(row = 1 , column = 0 )
  Label(lf1, text = "Q Q:" ).grid(row = 2 , column = 0 )
  Label(lf1, text = "Email:" ).grid(row = 3 , column = 0 )
  con = sqlite3.connect(r "D:\Python练习\作业\12月6日python\card.db" )
  print (n + "好靓仔" )
  cur = con.execute( "select * from card where name ==" + "'"+n+"'" )
  print ( "'"+n+"'" )
  for i in cur:
  print (i[ 0 ] + i[ 1 ] + i[ 2 ] + i[ 3 ])
  Label(lf1, text = i[ 0 ], width = 20 , anchor = W).grid(row = 0 , column = 1 , columnspan = 2 )
  Label(lf1, text = i[ 1 ], width = 20 , anchor = W).grid(row = 1 , column = 1 , columnspan = 2 )
  Label(lf1, text = i[ 2 ], width = 20 , anchor = W).grid(row = 2 , column = 1 , columnspan = 2 )
  Label(lf1, text = i[ 3 ], width = 20 , anchor = W).grid(row = 3 , column = 1 , columnspan = 2 )
  name = Entry(lf1)
  name.grid(row = 0 , column = 3 , columnspan = 2 )
  phone = Entry(lf1)
  phone.grid(row = 1 , column = 3 , columnspan = 2 )
  qq = Entry(lf1)
  qq.grid(row = 2 , column = 3 , columnspan = 2 )
  email = Entry(lf1)
  email.grid(row = 3 , column = 3 , columnspan = 2 )
  Label(lf1,text = "提示!修改名片在空白处输入确认修改即可" ,anchor = E).grid(row = 4 , column = 0 , columnspan = 3 )
  def xg_event(n):
  print (n)
  print (name.get())
  con = sqlite3.connect(r "D:\Python练习\作业\12月6日python\card.db" )
  con.execute( "update card set name=?,phone=?,qq=?,email=? where name =" + "'"+n+"'" ,(name.get(),phone.get(),qq.get(),email.get()))
  con.commit()
  con.close()
  update.destroy()
  show_all()
 
  #删除名片
  def delete(n):
  con = sqlite3.connect(r "D:\Python练习\作业\12月6日python\card.db" )
  con.execute( "delete from card where name =" + "'"+n+"'" )
  con.commit()
  con.close()
  show_all()
  showinfo(title = "提示" , message = "已删除!" )
  update.destroy()
  Button(lf1, text = "修 改" , command = lambda : xg_event(n)).grid(row = 5 , column = 2 , sticky = E)
  Button(lf1, text = "删 除" , command = lambda : delete(n)).grid(row = 5 , column = 1 , sticky = E)
 
 
#退出系统
def quit():
  root.destroy()
 
 
def about():
  showinfo(title = "关于我们" ,message = "卡片管理系统\n版本号:V4.0 \n作者:华浩新\n完成日期:2019年12月18日" )
 
  #创建一个Tk根窗口组件root
root = Tk()
root.title( "名片管理系统" )
root[ "width" ] = 800
root[ "height" ] = 500
 
 
#系统管理菜单栏
mubar = Menu(root)
muLogin = Menu(mubar,tearoff = 0 )
mubar.add_cascade(label = "系统管理" ,menu = muLogin)
muLogin.add_command(label = "加载数据" ,command = show_all)
muLogin.add_command(label = "清空数据" ,command = del_all)
tc = muLogin.add_command(label = "退出" ,command = quit)
 
#名片管理菜单栏
muCard = Menu(mubar,tearoff = 0 )
mubar.add_cascade(label = "名片管理" ,menu = muCard)
muCard.add_command(label = "显示所有" ,command = show_all)
root.bind( "<Button-1>," )
muCard.add_command(label = "新建" ,command = add)
muCard.add_command(label = "查找" ,command = search_card)
muCard.add_command(label = "保存" )
 
#帮助菜单栏
muHelp = Menu(mubar,tearoff = 0 )
mubar.add_cascade(label = "帮助" ,menu = muHelp)
muHelp.add_command(label = "关于" ,command = about)
t = Text(root,width = 100 ,height = 30 )
t.pack()
 
 
 
dataTreeview = ttk.Treeview(root, height = 19 ,show = 'headings' , column = ( 'name' , 'phone' , 'QQ' , 'email' ))
dataTreeview.column( 'name' , width = 80 , anchor = "center" )
dataTreeview.column( 'phone' , width = 80 , anchor = "center" )
dataTreeview.column( 'QQ' , width = 80 , anchor = "center" )
dataTreeview.column( 'email' , width = 80 , anchor = "center" )
 
dataTreeview.heading( 'name' , text = '姓名' )
dataTreeview.heading( 'phone' , text = '电话' )
dataTreeview.heading( 'QQ' , text = 'QQ' )
dataTreeview.heading( 'email' , text = '邮箱' )
dataTreeview.place(rely = 0 , relwidth = 1 )
Label(root, text = '名片管理系统V4.0' , bg = 'white' , fg = 'blue' , font = ( '宋体' , 15 )).pack(side = BOTTOM, fill = 'x' )
 
root[ "menu" ] = mubar
root.mainloop()

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持我.

原文链接:https://blog.csdn.net/weixin_42472371/article/details/103869906 。

最后此篇关于使用python实现名片管理系统的文章就讲到这里了,如果你想了解更多关于使用python实现名片管理系统的内容请搜索CFSDN的文章或继续浏览相关文章,希望大家以后支持我的博客! 。

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com