Hello,
I would like some guidance on a question / problem I have.
I'm doing a task that consists of an inventory system, things so far very well.
I have made a tkinter window with a "notebook" menu, (inventory/sale)
In notebook 1 I have done a "treeview" that shows mysql data, and buttons to add, delete and update product, so far everything is perfect.
The question I have now is when creating "notebook 2" (sales), that I will make another Treeview and show the same data, but my question is how can I update the "2 Treeviews" at the same time. Because only the one I interacted with is updated, and the other treeview is updated when I interact or restart the application.
I have thought about after(), but I don't know if it is a good option or there is another option.
Any additional information would be appreciated.
What I have tried:
Hi, I've tried it but when I change the tab (notebook) it doesn't update, I have to close and open the program again to see the update.
I'm trying after() but still the same
from tkinter import *
from tkinter import ttk
import tkinter as tk
import pymysql
from conexion import *
from tkinter import messagebox
from PIL import Image, ImageTk
from globales import VariablesGlobales
import threading
class Menuventas:
def __init__(self, ventas):
self.ventas = ventas
self.boton = ttk.Button(self.ventas.tab3, text="Haz clic")
self.boton.place(x=10, y=10, width=160, height=40)
self.variables_globales = VariablesGlobales()
def cargar_datos():
self.connection3 = connect_to_database()
self.cursor3 = self.connection3.cursor()
print(self.variables_globales.variable_global1)
self.cursor3.execute("SELECT * FROM almacen WHERE id_usuario = '"+self.variables_globales.variable_global1+"' ORDER BY id DESC")
self.datos_treeview = self.cursor3.fetchall()
for self.colun in self.datos_treeview:
self.c_id = self.colun[0]
self.c_producto = self.colun[1]
self.c_precio_compra = self.colun[2]
self.c_precio_venta = self.colun[3]
self.c_stock = self.colun[4]
self.c_proveedor = self.colun[5]
self.c_categoria = self.colun[6]
self.treeview_almacen.insert("", "end", values=(self.c_id, self.c_producto, self.c_precio_compra, self.c_precio_venta, self.c_stock, self.c_proveedor, self.c_categoria))
self.treeview_almacen.after(1000, cargar_datos)
self.treeview_almacen = ttk.Treeview(self.ventas.tab3, columns=("codigo","producto", "precio_compra", "precio_venta", "stock", "proovedor", "categoria"))
self.treeview_almacen.place(x=20, y=210, width=1085, height=340)
self.treeview_almacen.heading("#0", text="")
self.treeview_almacen.heading("codigo", text="CÓDIGO")
self.treeview_almacen.heading("producto", text="PRODUCTO")
self.treeview_almacen.heading("precio_compra", text="PRECIO COMPRA")
self.treeview_almacen.heading("precio_venta", text="PRECIO VENTA")
self.treeview_almacen.heading("stock", text="STOCK")
self.treeview_almacen.heading("proovedor", text="PROVEEDOR")
self.treeview_almacen.heading("categoria", text="CATEGORÍA")
self.treeview_almacen.column("#0", width=0)
self.treeview_almacen.column("codigo", width=100)
self.treeview_almacen.column("producto", width=200)
self.treeview_almacen.column("precio_compra", width=50)
self.treeview_almacen.column("precio_venta", width=50)
self.treeview_almacen.column("stock", width=40)
self.treeview_almacen.column("proovedor", width=130)
self.treeview_almacen.column("categoria", width=100)
self.scrollbar_y = tk.Scrollbar(self.ventas.tab3, orient="vertical", command=self.treeview_almacen.yview)
self.treeview_almacen.configure(yscrollcommand=self.scrollbar_y.set)
self.scrollbar_y.pack(side="right", fill="y")
cargar_datos()
self.update_thread = threading.Thread(target=cargar_datos)
self.update_thread.start()