tkinter - Update label content on click using Python -
I am trying to update the content of a button, in Python, by clicking on a button For each click, a counter will be raised and the value of the label will be updated with the current value of the counter (J). Here is the code:
Import time import import import imported from MySQLdb Tkinter import * j = 0 def PrintNumber (): global JJ + = 1 print j returns mgui = Tk ( ) Mgui.geometry ('200x200') mgui.title ('cue system') st = button (mgui, text = "next customer", command = print number) st.pack () f = PrintNumber () label = label ( Mgui, text = f) label. Pack () mgui.mainloop () Please kindly, I'm new in Python :)
You can use a tincynt instance to keep a value. If you assign the textvariable option to the variable label widget for the variable class, it will automatically update as the value of the example changes. Here is an example: Setting the Twinter import * root = Tk () var = IntVar () # from IntVar variable class var.set (0) # as the starting value # Button command is a lambda expression set on var Method calls, logic button (root, text = "next customer", command = lambda: var.set (Var.get (+ 1)) with 1 with # var value (var.get). The TextWire label of the Pack () # label is set to the variable class example label (root, text variable = var). Pack () Menloop ()
Comments
Post a Comment