python学生成绩管理系统有可视化界面连接mysql
时间: 2024-02-03 20:45:08 浏览: 34
是的,您可以使用Python中的Tkinter库来创建可视化界面,并使用Python的MySQL连接器来连接MySQL数据库。以下是一个简单的示例:
```python
import tkinter as tk
import mysql.connector
# 连接MySQL数据库
mydb = mysql.connector.connect(
host="localhost",
user="yourusername",
password="yourpassword",
database="yourdatabase"
)
# 创建可视化界面
root = tk.Tk()
root.title("学生成绩管理系统")
# 添加组件
label1 = tk.Label(root, text="学号")
label1.grid(row=0, column=0)
entry1 = tk.Entry(root)
entry1.grid(row=0, column=1)
label2 = tk.Label(root, text="姓名")
label2.grid(row=1, column=0)
entry2 = tk.Entry(root)
entry2.grid(row=1, column=1)
label3 = tk.Label(root, text="语文")
label3.grid(row=2, column=0)
entry3 = tk.Entry(root)
entry3.grid(row=2, column=1)
label4 = tk.Label(root, text="数学")
label4.grid(row=3, column=0)
entry4 = tk.Entry(root)
entry4.grid(row=3, column=1)
label5 = tk.Label(root, text="英语")
label5.grid(row=4, column=0)
entry5 = tk.Entry(root)
entry5.grid(row=4, column=1)
# 添加保存按钮
def save():
# 获取表单数据
student_id = entry1.get()
name = entry2.get()
chinese = entry3.get()
math = entry4.get()
english = entry5.get()
# 将数据插入MySQL数据库
cursor = mydb.cursor()
sql = "INSERT INTO students (student_id, name, chinese, math, english) VALUES (%s, %s, %s, %s, %s)"
val = (student_id, name, chinese, math, english)
cursor.execute(sql, val)
mydb.commit()
print(cursor.rowcount, "记录插入成功。")
save_button = tk.Button(root, text="保存", command=save)
save_button.grid(row=5, column=1)
root.mainloop()
```
在这个例子中,我们创建了一个包含学号、姓名和三门课程成绩的表单,并且添加了一个保存按钮,用于将表单数据保存到MySQL数据库中。您可以根据自己的需求修改表单的字段和按钮的功能。同时,您需要将数据库连接信息替换为您自己的信息。
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![doc](https://img-home.csdnimg.cn/images/20210720083327.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)