最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Python實(shí)現(xiàn)圖書管理系統(tǒng)設(shè)計(jì)

 更新時(shí)間:2022年03月10日 07:59:37   作者:程序猿o  
這篇文章主要為大家詳細(xì)介紹了Python實(shí)現(xiàn)圖書管理系統(tǒng)設(shè)計(jì),文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

基于python的tkinter,將圖書管理系統(tǒng)的界面進(jìn)行簡(jiǎn)單的開發(fā),我在這里使用的方法比較簡(jiǎn)單理解,但是代碼過(guò)于繁多。添加、刪除及修改并未使用數(shù)據(jù)庫(kù),而是使用了csv文件的讀取操作,從而替代數(shù)據(jù)庫(kù)。

基本效果如下圖所示:

該系統(tǒng)將所有代碼全都放在一個(gè)文件中,源碼如下:

import os
import tkinter
import tkinter.messagebox
from tkinter import *
from tkinter import ttk
?
class LoginPage (object):
? ? def __init__(self, master=None):?
? ? ? ? self.root = master #定義內(nèi)部變量root?
? ? ? ? # 獲取當(dāng)前屏幕的寬高
? ? ? ? self.width = self.root.winfo_screenwidth()
? ? ? ? self.height = self.root.winfo_screenheight()
? ? ? ? # 設(shè)置窗口大小
? ? ? ? self.h = 600
? ? ? ? self.w = 800
? ? ? ? # 將窗口居中
? ? ? ? self.y = (self.height - 600) / 2
? ? ? ? self.x = (self.width - 800) / 2
? ? ? ? self.root.geometry("%dx%d+%d+%d" %(self.w,self.h,self.x,self.y))
? ? ? ? # 不允許修改窗口大小
? ? ? ? self.root.resizable(False,False)
? ? ? ? self.addnum = StringVar()?
? ? ? ? self.addname = StringVar()?
? ? ? ? self.addauthor = StringVar()?
? ? ? ? self.addchu = StringVar()?
? ? ? ? self.adddate = StringVar()?
? ? ? ? self.addpri = StringVar()?
? ? ? ? self.altnum = StringVar()?
? ? ? ? self.altname = StringVar()?
? ? ? ? self.altauthor = StringVar()?
? ? ? ? self.altchu = StringVar()?
? ? ? ? self.altdate = StringVar()?
? ? ? ? self.altpri = StringVar()?
? ? ? ? self.createPage()?
?
? ? # 創(chuàng)建頁(yè)面
? ? def createPage(self):?
? ? ? ? #表格
? ? ? ? tree = ttk.Treeview(self.root)
? ? ? ? tree.place(x=10,y=10,width=780,height=260)
? ? ? ? # #定義列
? ? ? ? tree["columns"] = ("編號(hào)","書名","作者", "出版社", "出版日期", "價(jià)格")
? ? ? ? tree['show'] = 'headings'
? ? ? ? # 設(shè)置列,列還不顯示
? ? ? ? tree.column("編號(hào)", width=80,anchor ='c')
? ? ? ? tree.column("書名", width=150,anchor ='c')
? ? ? ? tree.column("作者", width=150,anchor ='c')
? ? ? ? tree.column("出版社", width=150,anchor ='c')
? ? ? ? tree.column("出版日期", width=150,anchor ='c')
? ? ? ? tree.column("價(jià)格", width=100,anchor ='c')
? ? ? ? #設(shè)置表頭
? ? ? ? tree.heading("編號(hào)", text="編號(hào)")
? ? ? ? tree.heading("書名", text="書名")
? ? ? ? tree.heading("作者", text="作者")
? ? ? ? tree.heading("出版社", text="出版社")
? ? ? ? tree.heading("出版日期", text="出版日期")
? ? ? ? tree.heading("價(jià)格", text="價(jià)格")
? ? ? ? #添加數(shù)據(jù)
? ? ? ? f = open('圖書.csv','r',encoding='utf-8')
? ? ? ? for line in f.readlines():
? ? ? ? ? ? info = line[:-1].split(",")
? ? ? ? ? ? tree.insert("", 0, values=(info[0],info[1],info[2],info[3],info[4],info[5]))
? ? ? ? f.close()
?
? ? ? ? # 添加編號(hào)
? ? ? ? addnum = Label(self.root, text="編號(hào)",font=('微軟雅黑',10,''),anchor='w')
? ? ? ? addnum.place(x=42.5,y=280,height=20,width=80)
? ? ? ? addnuminput = Entry(self.root,font=('微軟雅黑',10,''),textvariable=self.addnum)
? ? ? ? addnuminput.place(x=122.5,y=279,height=24,width=105)
? ? ? ? # 添加書名
? ? ? ? addname = Label(self.root, text="書名",font=('微軟雅黑',10,''),anchor='w')
? ? ? ? addname.place(x=42.5,y=310,height=20,width=80)
? ? ? ? addnameinput = Entry(self.root,font=('微軟雅黑',10,''),textvariable=self.addname)
? ? ? ? addnameinput.place(x=122.5,y=309,height=24,width=105)
? ? ? ? # 添加作者
? ? ? ? addauthor = Label(self.root, text="作者",font=('微軟雅黑',10,''),anchor='w')
? ? ? ? addauthor.place(x=42.5,y=340,height=20,width=80)
? ? ? ? addauthorinput = Entry(self.root,font=('微軟雅黑',10,''),textvariable=self.addauthor)
? ? ? ? addauthorinput.place(x=122.5,y=339,height=24,width=105)
? ? ? ? # 添加出版社
? ? ? ? addchu = Label(self.root, text="出版社",font=('微軟雅黑',10,''),anchor='w')
? ? ? ? addchu.place(x=42.5,y=370,height=20,width=80)
? ? ? ? addchuinput = Entry(self.root,font=('微軟雅黑',10,''),textvariable=self.addchu)
? ? ? ? addchuinput.place(x=122.5,y=369,height=24,width=105)
? ? ? ? # 添加出版日期
? ? ? ? adddate = Label(self.root, text="出版日期",font=('微軟雅黑',10,''),anchor='w')
? ? ? ? adddate.place(x=42.5,y=400,height=20,width=80)
? ? ? ? adddateinput = Entry(self.root,font=('微軟雅黑',10,''),textvariable=self.adddate)
? ? ? ? adddateinput.place(x=122.5,y=399,height=24,width=105)
? ? ? ? # 添加價(jià)格
? ? ? ? addpri = Label(self.root, text="價(jià)格",font=('微軟雅黑',10,''),anchor='w')
? ? ? ? addpri.place(x=42.5,y=430,height=20,width=80)
? ? ? ? addpriinput = Entry(self.root,font=('微軟雅黑',10,''),textvariable=self.addpri)
? ? ? ? addpriinput.place(x=122.5,y=429,height=24,width=105)
? ? ? ? # 添加按鈕
? ? ? ? add = Button(self.root,command=self.click, text ="添加書本",font=('微軟雅黑',10,''),activeforeground='#ffffff',fg='#ffffff',activebackground='#7cba59',bd=2,bg='#2aa515')
? ? ? ? add.place(x=105,y=500,height=35,width=100)
?
?
? ? ? ? # 修改編號(hào)
? ? ? ? altnum = Label(self.root, text="編號(hào)",font=('微軟雅黑',10,''),anchor='w')
? ? ? ? altnum.place(x=292.5,y=280,height=20,width=80)
? ? ? ? altnuminput = Entry(self.root,font=('微軟雅黑',10,''),textvariable=self.altnum)
? ? ? ? altnuminput.place(x=372.5,y=279,height=24,width=105)
? ? ? ? # 修改書名
? ? ? ? altname = Label(self.root, text="書名",font=('微軟雅黑',10,''),anchor='w')
? ? ? ? altname.place(x=292.5,y=310,height=20,width=80)
? ? ? ? altnameinput = Entry(self.root,font=('微軟雅黑',10,''),textvariable=self.altname)
? ? ? ? altnameinput.place(x=372.5,y=309,height=24,width=105)
? ? ? ? # 修改作者
? ? ? ? altauthor = Label(self.root, text="作者",font=('微軟雅黑',10,''),anchor='w')
? ? ? ? altauthor.place(x=292.5,y=340,height=20,width=80)
? ? ? ? altauthorinput = Entry(self.root,font=('微軟雅黑',10,''),textvariable=self.altauthor)
? ? ? ? altauthorinput.place(x=372.5,y=339,height=24,width=105)
? ? ? ? # 修改出版社
? ? ? ? altchu = Label(self.root, text="出版社",font=('微軟雅黑',10,''),anchor='w')
? ? ? ? altchu.place(x=292.5,y=370,height=20,width=80)
? ? ? ? altchuinput = Entry(self.root,font=('微軟雅黑',10,''),textvariable=self.altchu)
? ? ? ? altchuinput.place(x=372.5,y=369,height=24,width=105)
? ? ? ? # 修改出版日期
? ? ? ? altdate = Label(self.root, text="出版日期",font=('微軟雅黑',10,''),anchor='w')
? ? ? ? altdate.place(x=292.5,y=400,height=20,width=80)
? ? ? ? altdateinput = Entry(self.root,font=('微軟雅黑',10,''),textvariable=self.altdate)
? ? ? ? altdateinput.place(x=372.5,y=399,height=24,width=105)
? ? ? ? # 修改價(jià)格
? ? ? ? altpri = Label(self.root, text="價(jià)格",font=('微軟雅黑',10,''),anchor='w')
? ? ? ? altpri.place(x=292.5,y=430,height=20,width=80)
? ? ? ? altpriinput = Entry(self.root,font=('微軟雅黑',10,''),textvariable=self.altpri)
? ? ? ? altpriinput.place(x=372.5,y=429,height=24,width=105)
? ? ? ? # 修改按鈕
? ? ? ? alter = Button(self.root,command=self.altclick, text ="修改書本",font=('微軟雅黑',10,''),activeforeground='#ffffff',fg='#ffffff',activebackground='#7cba59',bd=2,bg='#2aa515')
? ? ? ? alter.place(x=350,y=500,height=35,width=100)
? ? ? ? # 保存按鈕
? ? ? ? pre = Button(self.root,command=self.show, text ="保存書本信息",font=('微軟雅黑',10,''),activeforeground='#ffffff',fg='#ffffff',activebackground='#7cba59',bd=2,bg='#2aa515')
? ? ? ? pre.place(x=595,y=500,height=35,width=100)
?
? ? # 寫入判斷輸入框是否有空值
? ? def Isspace(self,text):
? ? ? ? temp = 0
? ? ? ? for i in text:
? ? ? ? ? ?if not i.isspace():
? ? ? ? ? ? ? ?temp = 1
? ? ? ? ? ? ? ?break
? ? ? ? if temp==1:
? ? ? ? ? ? return 0
? ? ? ? else:
? ? ? ? ? ? return 1
? ? # 檢查寫入是否有空值
? ? def click(self):
? ? ? ? addnum = self.addnum.get()
? ? ? ? addname = self.addname.get()
? ? ? ? addauthor = self.addauthor.get()
? ? ? ? addchu = self.addchu.get()
? ? ? ? adddate = self.adddate.get()
? ? ? ? addpri = self.addpri.get()
? ? ? ? if self.Isspace(addnum) or self.Isspace(addname) or self.Isspace(addauthor) or self.Isspace(addchu) or self.Isspace(adddate) or self.Isspace(addpri) :
? ? ? ? ? ? tkinter.messagebox.showerror(title='提示', message ="請(qǐng)?zhí)顚懰行畔?)
? ? ? ? else:
? ? ? ? ? ? self.write(addnum,addname,addauthor,addchu,adddate,addpri)
? ? # 寫入信息
? ? def write(self,addnum,addname,addauthor,addchu,adddate,addpri):
? ? ? ? f = open('圖書.csv','r',encoding='utf-8')
? ? ? ? for line in f.readlines():
? ? ? ? ? ? info = line[:-1].split(",")
? ? ? ? ? ? if len(info)<6:
? ? ? ? ? ? ? ? break
? ? ? ? ? ? if info[0] ==addnum and info[1] ==addname:
? ? ? ? ? ? ? ? ?tkinter.messagebox.showinfo(title='結(jié)果', message ="已存在該圖書信息!")
? ? ? ? ? ? ? ? ?f.close()
? ? ? ? ? ? ? ? ?return
?
? ? ? ? f.close()
? ? ? ? f = open('圖書.csv','a',encoding='utf-8')
? ? ? ? f.write('{},{},{},{},{},{}\n'.format(addnum,addname,addauthor,addchu,adddate,addpri))
? ? ? ? f.close()
? ? ? ? tkinter.messagebox.showinfo(title='提示', message ="寫入成功,點(diǎn)擊保存后更新")
?
? ? # 檢查修改信息是否空白
? ? def altclick(self):
? ? ? ? altnum = self.altnum.get()
? ? ? ? altname = self.altname.get()
? ? ? ? altauthor = self.altauthor.get()
? ? ? ? altchu = self.altchu.get()
? ? ? ? altdate = self.altdate.get()
? ? ? ? altpri = self.altpri.get()
? ? ? ? if self.Isspace(altnum) or self.Isspace(altname) or self.Isspace(altauthor) or self.Isspace(altchu) or self.Isspace(altdate) or self.Isspace(altpri) :
? ? ? ? ? ? tkinter.messagebox.showerror(title='提示', message ="輸入項(xiàng)為空")
? ? ? ? else:
? ? ? ? ? ? self.modify(altnum,altname,altauthor,altchu,altdate,altpri)
?
? ? # 修改信息
? ? def modify(self,altnum,altname,altauthor,altchu,altdate,altpri):
? ? ? ? temp = 0
? ? ? ? with open("圖書.csv","r",encoding="utf-8") as f:
? ? ? ? ? ? lines = f.readlines()
? ?
? ? ? ? with open("圖書.csv","w",encoding="utf-8") as f_w:
? ? ? ? ? ? for line in lines:
? ? ? ? ? ? ? ? info = line[:-1].split(",")
? ? ? ? ? ? ? ? if info[0] ==altnum:
? ? ? ? ? ? ? ? ? ? temp = 1
? ? ? ? ? ? ? ? ? ? f_w.write('{},{},{},{},{},{}\n'.format(altnum,altname,altauthor,altchu,altdate,altpri))
? ? ? ? ? ? ? ? ? ? continue
? ? ? ? ? ? ? ? f_w.write(line)
? ? ? ? if temp==0:
? ? ? ? ? ? tkinter.messagebox.showerror(title='提示', message ="沒有該信息")
? ? ? ? else:
? ? ? ? ? ? tkinter.messagebox.showinfo(title='提示', message ="修改成功,點(diǎn)擊保存后更新")
? ? # 保存信息并顯示
? ? def show(self):
? ? ? ? self.createPage()?
root = Tk()?
root.title('圖書管理')?
LoginPage(root)?
root.mainloop()?

在運(yùn)行代碼前需要在同級(jí)文件夾下創(chuàng)建一個(gè)名為“圖書”的csv文件,如下圖所示:

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • python中的各種運(yùn)算符介紹

    python中的各種運(yùn)算符介紹

    這篇文章主要介紹了python中的各種運(yùn)算符,主要包括內(nèi)容有比較運(yùn)算符、?賦值運(yùn)算符、位運(yùn)算符、邏輯運(yùn)算符、?成員運(yùn)算符的相關(guān)介紹,需要的小伙伴可以參考一下
    2022-04-04
  • 淺談python中set使用

    淺談python中set使用

    下面小編就為大家?guī)?lái)一篇淺談python中set使用。小編覺得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧
    2016-06-06
  • Python實(shí)現(xiàn)識(shí)別手寫數(shù)字 Python圖片讀入與處理

    Python實(shí)現(xiàn)識(shí)別手寫數(shù)字 Python圖片讀入與處理

    這篇文章主要為大家詳細(xì)介紹了Python實(shí)現(xiàn)識(shí)別手寫數(shù)字,Python圖片的讀入與處理,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2018-01-01
  • Python3實(shí)現(xiàn)打印任意寬度的菱形代碼

    Python3實(shí)現(xiàn)打印任意寬度的菱形代碼

    這篇文章主要介紹了Python3實(shí)現(xiàn)打印任意寬度的菱形代碼,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧
    2020-04-04
  • python輸出小數(shù)精度控制的方法

    python輸出小數(shù)精度控制的方法

    這篇文章主要介紹了python輸出小數(shù)控制的方法示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2022-05-05
  • Python3.9.1中使用match方法詳解

    Python3.9.1中使用match方法詳解

    這篇文章主要介紹了Python3.9.1中使用match方法詳解,本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2021-02-02
  • 全面介紹python中很常用的單元測(cè)試框架unitest

    全面介紹python中很常用的單元測(cè)試框架unitest

    這篇文章主要介紹了python中很常用的單元測(cè)試框架unitest的相關(guān)資料,幫助大家更好的利用python進(jìn)行單元測(cè)試,感興趣的朋友可以了解下
    2020-12-12
  • Python編譯為二進(jìn)制so可執(zhí)行文件實(shí)例

    Python編譯為二進(jìn)制so可執(zhí)行文件實(shí)例

    今天小編就為大家分享一篇Python編譯為二進(jìn)制so可執(zhí)行文件實(shí)例,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧
    2019-12-12
  • 基于Python編寫一個(gè)簡(jiǎn)單的服務(wù)注冊(cè)發(fā)現(xiàn)服務(wù)器

    基于Python編寫一個(gè)簡(jiǎn)單的服務(wù)注冊(cè)發(fā)現(xiàn)服務(wù)器

    我們都知道有很多的非常著名的注冊(cè)服務(wù)器,例如:?Consul、ZooKeeper、etcd,甚至借助于redis完成服務(wù)注冊(cè)發(fā)現(xiàn)。但是本篇文章我們將使用python?socket寫一個(gè)非常簡(jiǎn)單的服務(wù)注冊(cè)發(fā)現(xiàn)服務(wù)器,感興趣的可以了解一下
    2023-04-04
  • python dataframe向下向上填充,fillna和ffill的方法

    python dataframe向下向上填充,fillna和ffill的方法

    今天小編就為大家分享一篇python dataframe向下向上填充,fillna和ffill的方法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧
    2018-11-11

最新評(píng)論

舞阳县| 新巴尔虎右旗| 涿鹿县| 务川| 台北市| 库车县| 金坛市| 丁青县| 鄱阳县| 西昌市| 罗田县| 万全县| 富蕴县| 淮安市| 乌鲁木齐市| 伊通| 余江县| 台中市| 玛纳斯县| 湖北省| 泸州市| 于都县| 巴林右旗| 涞源县| 芮城县| 德令哈市| 吉木萨尔县| 滨海县| 永和县| 绥宁县| 陈巴尔虎旗| 金华市| 潼关县| 道孚县| 江口县| 弋阳县| 元朗区| 巴楚县| 兴城市| 鱼台县| 辉南县|