Current situation : I have one GUI program(written by python) which using sqlite data stored on my computer.
Wishlist: I would like to have one server computer to locate sqlite data (DATA A1) (CRUD operation needed) and ten more client computer using GUI program(written by python) which connect with the sqlite data (DATA A1) on lan.
I have no idea how to set up this program and server and what I need to learn more.
Current example code for check product in shop:
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()
changing sqlite3 to 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
See Question&Answers more detail:os