I created a program used by several users via a hosting system.
The purpose of this program is when a user A click on the button change value, the buttons Color change and Generate text change state ( normal to disable) instantly. The users B must see the changement when they click on the tab 1 without restarting the program. The users don't have to restart the program to see the change. But here, my code works but the users have to restart the program to see the change made by other users... I don't want that. Is there any solution?
Thank you
from tkinter import *
import tkinter as tk
from tkinter import ttk
from tkinter.ttk import *
import sqlite3
root = Tk()
conn = sqlite3.connect( '/database' )
c = conn.cursor()
query = "SELECT var FROM state WHERE id=1"
c.execute( query )
var = c.fetchall()[0][0]
tab = ttk.Notebook( root ) # create notebook
tab.pack( expand = True, fill = tk.BOTH )
def changevalue() :
global var
query = "SELECT var FROM state WHERE id=1"
c.execute( query )
var = c.fetchall()[0][0]
if var == 1 :
query = "UPDATE state SET var=0 WHERE id=1"
conn.execute( query )
conn.commit()
button_1['state'] = 'normal'
button_2['state'] = 'normal'
if var == 0 :
query = "UPDATE state SET var=1 WHERE id=1"
conn.execute( query )
conn.commit()
button_1['state'] = 'disabled'
button_2['state'] = 'disabled'
# create Frames for tab
frame1 = ttk.Frame( tab )
frame1.pack( fill = "both" )
frame2 = ttk.Frame( tab )
frame2.pack( fill = "both" )
frame3 = ttk.Frame( tab )
frame3.pack( fill = "both" )
# Add frames
tab.add( frame1, text = 'Mytab1' )
tab.add( frame2, text = 'Mytab2' )
tab.add( frame3, text = 'Mytab3' )
# Button in each tab
button_1 = Button( frame1, text = "Color change" ).pack()
button_2 = Button( frame2, text = "Generate text" ).pack()
button_3 = Button( frame3, text = "change value", command = changevalue ).pack()
if var == 1 :
button_1 = Button( frame1, text = "Color change", state = 'disabled' )
button_2 = Button( frame2, text = "Generate text", state = 'disabled' )
else :
button_1 = Button( frame1, text = "Color change", state = 'normal' )
button_2 = Button( frame2, text = "Generate text", state = 'normal' )
root.mainloop()