帮我写一个用python tkinter 写的记录人员信息并且把信息存到数据库记录人员的姓名,地址,金额,备注
时间: 2023-03-29 07:01:27 浏览: 67
好的,我可以回答这个问题。以下是一个简单的 Python Tkinter 界面,可以记录人员信息并将其存储到数据库中:
```python
import tkinter as tk
import sqlite3
# 创建数据库连接
conn = sqlite3.connect('person_info.db')
c = conn.cursor()
# 创建表格
c.execute('''CREATE TABLE IF NOT EXISTS person_info
(name TEXT, address TEXT, amount REAL, note TEXT)''')
# 定义函数,将信息插入数据库
def insert_info():
name = name_entry.get()
address = address_entry.get()
amount = amount_entry.get()
note = note_entry.get()
c.execute("INSERT INTO person_info VALUES (?, ?, ?, ?)", (name, address, amount, note))
conn.commit()
# 创建界面
root = tk.Tk()
root.title("记录人员信息")
# 创建标签和输入框
name_label = tk.Label(root, text="姓名")
name_label.grid(row=, column=)
name_entry = tk.Entry(root)
name_entry.grid(row=, column=1)
address_label = tk.Label(root, text="地址")
address_label.grid(row=1, column=)
address_entry = tk.Entry(root)
address_entry.grid(row=1, column=1)
amount_label = tk.Label(root, text="金额")
amount_label.grid(row=2, column=)
amount_entry = tk.Entry(root)
amount_entry.grid(row=2, column=1)
note_label = tk.Label(root, text="备注")
note_label.grid(row=3, column=)
note_entry = tk.Entry(root)
note_entry.grid(row=3, column=1)
# 创建按钮,将信息插入数据库
submit_button = tk.Button(root, text="提交", command=insert_info)
submit_button.grid(row=4, column=1)
root.mainloop()
```
这个程序将创建一个名为 `person_info.db` 的 SQLite 数据库,并在其中创建一个名为 `person_info` 的表格,用于存储人员信息。用户可以在界面上输入人员的姓名、地址、金额和备注,并点击“提交”按钮将信息插入数据库。
相关推荐
![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)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_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)