赞
踩
我们先看一下效果图。
1:登录界面:
2:
查询数据库所有的内容!
3:
4:最终的打包!
话不多说直接上代码!!!!
from tkinter import *
import pymysql
from tkinter.messagebox import *
from tkinter import ttk
def get_connect():
conn = pymysql.connect(host=‘localhost’, user=“root”, passwd=‘GAO147258369’,database=‘stu’)
return conn
window = Tk()
window.geometry(‘500x300’)
window.title(‘登录账号!’)
def create():
root =Toplevel()
root.geometry(‘700x800’)
root.title(‘学生管理系统’)
Label(root, text=“学号:”).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)
sid1 = StringVar()
name1 = StringVar()
sex1 = StringVar()
phone = StringVar()
Entry(root, textvariable=sid1).place(relx=0.1, rely=0.05, relwidth=0.37, height=25)
Entry(root, textvariable=name1).place(relx=0.6, rely=0.05, relwidth=0.37, height=25)
Entry(root, textvariable=sex1).place(relx=0.1, rely=0.1, relwidth=0.37, height=25)
Entry(root, textvariable=phone).place(relx=0.6, rely=0.1, relwidth=0.37, height=25)
def add():
list1 = []
list1.append(sid1.get())
list1.append(name1.get())
list1.append(sex1.get())
list1.append(phone.get())
connection = get_connect()
cur = connection.cursor(cursor=pymysql.cursors.DictCursor)
sql = ‘insert into student(学号,姓名,性别,电话) values(“%s”,“%s”,“%s”, “%s”)’
sid = int(list1[0])
name = list1[1]
sex = list1[2]
iphone = int(list1[3])
try:
cur.execute(sql % (sid, name, sex, iphone))
connection.commit()
except Exception as e:
connection.rollback()
raise e
finally:
connection.close()
showinfo(‘提示’, ‘添加成功!’)
def search():
showinfo(‘提示’, ‘请输入学号!’)
into = int(sid1.get())
conn = pymysql.connect(host=‘localhost’, user=“root”, passwd=“”, database=‘stu’)
cur = conn.cursor()
sql = ‘select * from student ;’
cur.execute(sql)
all = cur.fetchall()
for i in range(len(all)):
for j in all:
if into == j[0]:
treeview.insert(‘’, i, value=(j[0], j[1], j[2], j[3]))
break
break
def search_all():
conn = pymysql.connect(host=‘localhost’, user=“root”, passwd=“”, database=‘stu’)
针对最近很多人都在面试,我这边也整理了相当多的面试专题资料,也有其他大厂的面经。希望可以帮助到大家。
下面的面试题答案都整理成文档笔记。也还整理了一些面试资料&最新2021收集的一些大厂的面试真题(都整理成文档,小部分截图)
最新整理电子书
多人都在面试,我这边也整理了相当多的面试专题资料,也有其他大厂的面经。希望可以帮助到大家。
下面的面试题答案都整理成文档笔记。也还整理了一些面试资料&最新2021收集的一些大厂的面试真题(都整理成文档,小部分截图)
[外链图片转存中…(img-RhdIGRdt-1714438238146)]
最新整理电子书
[外链图片转存中…(img-LAa3bwIs-1714438238147)]
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。