【发布时间】:2021-06-15 04:09:35
【问题描述】:
当前情况:我有一个 GUI 程序(由 python 编写),它使用存储在我计算机上的 sqlite 数据。
愿望清单:我想要一台服务器计算机来定位 sqlite 数据(DATA A1)(需要 CRUD 操作)和另外十台使用 GUI 程序(由 python 编写)的客户端计算机,它们与 sqlite 数据(DATA A1)连接局域网。
我不知道如何设置这个程序和服务器以及我需要了解更多信息。
当前在商店中检查产品的示例代码:
import sqlite3
from tkinter import *
from tkinter import ttk
GUI = Tk()
GUI.geometry('1280x720')
def connect_product_data():
global conn
global c
conn = sqlite3.connect('A1.db')
c = conn.cursor()
def pull_product_data():
global sqlselectdata
connect_product_data()
with conn:
c.execute("""SELECT * FROM PDLIST""",
)
sqlselectdata = c.fetchall()
conn.commit()
return sqlselectdata
tree_view_frame = Frame(GUI)
tree_view_frame.pack()
tree_scroll = Scrollbar(tree_view_frame)
tree_scroll.pack(side = RIGHT, fill = Y)
header = ['Part No.', 'Name', 'Price']
hdsize = [70,250,70]
aanchor = [W,W,E]
global product_table
product_table = ttk.Treeview(tree_view_frame, columns = header, show = 'headings', height = 20, yscrollcommand=tree_scroll.set, selectmode="extended")
def treeview_sort_column(product_table, col, reverse):
l = [(product_table.set(k, col), k) for k in product_table.get_children('')]
try:
l.sort(key=lambda t: float(t[0].replace(",","")), reverse=reverse)
except:
l.sort(reverse=reverse)
for index, (val, k) in enumerate(l):
product_table.move(k, '', index)
product_table.heading(col, command=lambda _col=col: treeview_sort_column(product_table, _col, not reverse))
for col in header:
product_table.heading(col, text=col,command=lambda _col=col: treeview_sort_column(product_table, _col, False))
product_table.pack()
tree_scroll.config(command = product_table.yview)
for h,s,a in zip(header, hdsize, aanchor):
product_table.heading(h, text = h)
product_table.column(h,width = s, anchor = a)
def check_Product():
A1data = pull_product_data()
if len(A1data)>0:
for v in A1data:
product_table.insert('', 'end', value = (v[0],v[1],v[2]))
B_check_product = ttk.Button(GUI, text = "Add Product", width = 15, command = check_Product)
B_check_product.pack()
GUI.mainloop()
将 sqlite3 更改为 MySQL:
def connect_product_data():
global mc
global conn
conn = mysql.connector.connect(
host="localhost",
user="root",
password="123456789",
database="mydatabase"
)
mc = conn.cursor()
def pull_product_data():
global sqlselectdata
connect_product_data()
mc.execute("SELECT * FROM customers")
sqlselectdata = mc.fetchall()
conn.commit()
return sqlselectdata
【问题讨论】: