python+tkinter實(shí)現(xiàn)學(xué)生管理系統(tǒng)
本文實(shí)例為大家分享了python+tkinter實(shí)現(xiàn)學(xué)生管理系統(tǒng)的具體代碼,供大家參考,具體內(nèi)容如下

from tkinter import *
from tkinter.messagebox import *
import sqlite3
from tkinter import ttk
dbstr = "H:\mydb.db"
root = Tk()
root.geometry('700x1000')
root.title('學(xué)生管理系統(tǒng)')
Label(root, text="學(xué)號(hào):").place(relx=0, rely=0.05, relwidth=0.1)
Label(root, text="姓名:").place(relx=0.5, rely=0.05, relwidth=0.1)
Label(root, text="電話:").place(relx=0, rely=0.1, relwidth=0.1)
Label(root, text="地址:").place(relx=0.5, rely=0.1, relwidth=0.1)
sid = StringVar()
name = StringVar()
phone = StringVar()
address = StringVar()
Entry(root, textvariable=sid).place(relx=0.1, rely=0.05, relwidth=0.37, height=25)
Entry(root, textvariable=name).place(relx=0.6, rely=0.05, relwidth=0.37, height=25)
Entry(root, textvariable=phone).place(relx=0.1, rely=0.1, relwidth=0.37, height=25)
Entry(root, textvariable=address).place(relx=0.6, rely=0.1, relwidth=0.37, height=25)
Label(root, text='學(xué)生信息管理', bg='white', fg='red', font=('宋體', 15)).pack(side=TOP, fill='x')
def showAllInfo():
x = dataTreeview.get_children()
for item in x:
dataTreeview.delete(item)
con = sqlite3.connect(dbstr)
cur = con.cursor()
cur.execute("select * from student")
lst = cur.fetchall()
for item in lst:
dataTreeview.insert("", 1, text="line1", values=item)
cur.close()
con.close()
def appendInfo():
if sid.get() == "":
showerror(title='提示', message='輸入不能為空')
elif name.get() == "":
showerror(title='提示', message='輸入不能為空')
elif phone.get() == "":
showerror(title='提示', message='輸入不能為空')
elif address.get() == "":
showerror(title='提示', message='輸入不能為空')
else:
x = dataTreeview.get_children()
for item in x:
dataTreeview.delete(item)
list1 = []
list1.append(sid.get())
list1.append(name.get())
list1.append(phone.get())
list1.append(address.get())
con = sqlite3.connect(dbstr)
cur = con.cursor()
cur.execute("insert into student values(?,?,?,?)", tuple(list1))
con.commit()
cur.execute("select * from student")
lst = cur.fetchall()
for item in lst:
dataTreeview.insert("", 1, text="line1", values=item)
cur.close()
con.close()
def deleteInfo():
con = sqlite3.connect(dbstr)
cur = con.cursor()
cur.execute("select * from student")
studentList = cur.fetchall()
cur.close()
con.close()
print(studentList)
num = sid.get()
flag = 0
if num.isnumeric() == False:
showerror(title='提示', message='刪除失敗')
for i in range(len(studentList)):
for item in studentList[i]:
if int(num) == item:
flag = 1
con = sqlite3.connect(dbstr)
cur = con.cursor()
cur.execute("delete from student where id = ?", (int(num),))
con.commit()
cur.close()
con.close()
break
if flag == 1:
showinfo(title='提示', message='刪除成功!')
else:
showerror(title='提示', message='刪除失敗')
x = dataTreeview.get_children()
for item in x:
dataTreeview.delete(item)
con = sqlite3.connect(dbstr)
cur = con.cursor()
cur.execute("select * from student")
lst = cur.fetchall()
for item in lst:
dataTreeview.insert("", 1, text="line1", values=item)
cur.close()
con.close()
Button(root, text="顯示所有信息", command=showAllInfo).place(relx=0.2, rely=0.2, width=100)
Button(root, text="追加信息", command=appendInfo).place(relx=0.4, rely=0.2, width=100)
Button(root, text="刪除信息", command=deleteInfo).place(relx=0.6, rely=0.2, width=100)
dataTreeview = ttk.Treeview(root, show='headings', column=('sid', 'name', 'phone', 'address'))
dataTreeview.column('sid', width=150, anchor="center")
dataTreeview.column('name', width=150, anchor="center")
dataTreeview.column('phone', width=150, anchor="center")
dataTreeview.column('address', width=150, anchor="center")
dataTreeview.heading('sid', text='學(xué)號(hào)')
dataTreeview.heading('name', text='名字')
dataTreeview.heading('phone', text='電話')
dataTreeview.heading('address', text='地址')
dataTreeview.place(rely=0.3, relwidth=0.97)
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- python實(shí)現(xiàn)學(xué)生管理系統(tǒng)
- python學(xué)生管理系統(tǒng)代碼實(shí)現(xiàn)
- Python基于mysql實(shí)現(xiàn)學(xué)生管理系統(tǒng)
- python版學(xué)生管理系統(tǒng)
- python Tkinter版學(xué)生管理系統(tǒng)
- 詳解用python實(shí)現(xiàn)基本的學(xué)生管理系統(tǒng)(文件存儲(chǔ)版)(python3)
- Python實(shí)現(xiàn)學(xué)生管理系統(tǒng)的完整代碼(面向?qū)ο?
- 基于python實(shí)現(xiàn)學(xué)生管理系統(tǒng)
- 基于Python實(shí)現(xiàn)簡(jiǎn)單學(xué)生管理系統(tǒng)
- Python實(shí)現(xiàn)功能全面的學(xué)生管理系統(tǒng)
相關(guān)文章
Python的類實(shí)例屬性訪問(wèn)規(guī)則探討
這篇文章主要介紹了Python的類實(shí)例屬性訪問(wèn)規(guī)則,本文總結(jié)了一些對(duì)C++和Java程序員來(lái)說(shuō)不是很直觀的地方來(lái)說(shuō)明Python中的類實(shí)例屬性訪問(wèn),需要的朋友可以參考下2015-01-01
python游戲?qū)崙?zhàn)項(xiàng)目之童年經(jīng)典超級(jí)瑪麗
史上十大最經(jīng)典小霸王游戲中魂斗羅只能排在第二,那么第一是誰(shuí)?最經(jīng)典最風(fēng)靡的當(dāng)屬超級(jí)瑪麗,那個(gè)戴帽子的大胡子穿著背帶褲的馬里奧哪個(gè)不認(rèn)得,小編帶你用python實(shí)現(xiàn)超級(jí)瑪麗緬懷童年2021-09-09
python區(qū)塊鏈地址的簡(jiǎn)版實(shí)現(xiàn)
這篇文章主要為大家介紹了python區(qū)塊鏈地址的簡(jiǎn)版實(shí)現(xiàn),有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-05-05
python深度學(xué)習(xí)tensorflow1.0參數(shù)初始化initializer
這篇文章主要為大家介紹了python深度學(xué)習(xí)tensorflow1.0參數(shù)初始化initializer示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-06-06
Python遞歸函數(shù)反轉(zhuǎn)序列的實(shí)現(xiàn)
本文主要介紹了Python遞歸函數(shù)反轉(zhuǎn)序列的實(shí)現(xiàn),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2023-07-07
Python+tkinter使用40行代碼實(shí)現(xiàn)計(jì)算器功能
這篇文章主要為大家詳細(xì)介紹了Python+tkinter使用40行代碼實(shí)現(xiàn)計(jì)算器功能,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2018-01-01

