-1

Is there a way to auto-refresh tableview from a database ? maybe with a button or auto ? I Created a Manual Refresh Visual Button to do the job "click_Refresh()" can any one help ?

CODE :

import ttkbootstrap as ttk
import cx_Oracle
from ttkbootstrap.tableview import Tableview
from ttkbootstrap.constants import *
from ttkbootstrap.toast import ToastNotification

dsn_tns = cx_Oracle.makedsn('****', '****', service_name='****')
con = cx_Oracle.connect(user=r'****', password='****', dsn=dsn_tns)
cur = con.cursor()
rowdata = cur.execute('''SELECT USER_ID,EMAIL,USER_STATUS from table
    ''')

def click_Refresh():
    # Display message
    toast.show_toast()

coldata = [
    {"text": "USER_ID", "stretch": True},
    {"text": "EMAIL", "stretch": True},
    {"text": "USER_STATUS", "stretch": True},
]

app = ttk.Window(themename="superhero", size=(100, 100))
app.geometry("1000x500")
app.title("USER MANAGEMENT")
app.resizable(True, True)
app.place_window_center()

label = ttk.Label(app, text="USER MANAGEMENT VERSION 1.0", bootstyle=DEFAULT)
label.pack(pady=5)
label.config(font=("Arial", 20, "bold"))

button_frame = ttk.Frame(app)
button_frame.pack(pady=10, padx=2, fill="x")
ttk.Button(button_frame, text="Refresh", bootstyle="OUTLINE-SUCCESS",
           command=click_Refresh).pack(side=LEFT, padx=10, pady=5)

dt = Tableview(
    master=app,  # The parent widget
    paginated=False,
    searchable=True,
    height=50,
    autoalign=False,
    autofit=True,
    pagesize=30,
    coldata=coldata,
    rowdata=rowdata,
    bootstyle=DANGER,
)

dt.pack(fill=BOTH, expand=YES, padx=10, pady=10)
dt.autofit_columns()  # Fit in current view


# Define the toast notice (temporary message)
toast = ToastNotification(
    title="Refresh Notifcation",
    message=("Database version:", cx_Oracle.version,
             "Database version:", con.version,
             "Client version:", cx_Oracle.clientversion()
             ),
    duration=9000,
    bootstyle=DARK,
    alert=True,
)

app.mainloop()

ChrisGPT was on strike
  • 127,765
  • 105
  • 273
  • 257
O7AC1
  • 1

1 Answers1

0

Could you use something like: app.after(3000, CheckStatus())

found this idea here: Tkinter after method executing immediately

MCSDev70
  • 1
  • 1
  • Many thanks for the IDEA. Will you help me with that? Do I have to create a function which repeats the cursor? def CheckStatus(self): rowdata = cur.execute('''SELECT USER_ID,EMAIL,USER_STATUS from table ''') app.after(3000, CheckStatus()) – O7AC1 Apr 24 '23 at 18:40
  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Apr 25 '23 at 22:43
  • I am still researching this... however, I am coming to understand that your table code in a function might be the way to go... again, researching. – MCSDev70 May 21 '23 at 20:30