生活随笔
收集整理的這篇文章主要介紹了
python实现名片管理系统(界面+数据库)
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
python實現名片管理系統(界面+數據庫)
開發一個簡單的信息管理系統(類似于前面的名片管理系統),要求:
1.用結構化方法或面向對象開發方法開發系統
2.有圖形用戶界面
3.用數據庫存儲數據
4.用python語言實現系統
部分功能如下圖
進入時的界面
顯示所有名片后的界面
新建名片功能
新建成功
查找名片里包含(修改名片和刪除名片)
具體代碼如下
import sys
from tkinter
import *
from tkinter
.messagebox
import *
from tkinter
import ttk
import sqlite3con
= sqlite3
.connect
(r
"D:\Python練習\作業\12月6日python\card.db")
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
)con
.commit
()con
.close
()add
.destroy
()show_all
()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
=0dataTreeview
.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)def sure():con
= sqlite3
.connect
(r
"D:\Python練習\作業\12月6日python\card.db")cur
= con
.execute
("select * from card")for i
in cur
:if name
.get
() == i
[0]:print("查找成功")update
(i
[0])search
.destroy
()breakelse: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日")
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
()
總結
以上是生活随笔為你收集整理的python实现名片管理系统(界面+数据库)的全部內容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。