Python Forum
[Tkinter] Trying to display a changing variable
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Tkinter] Trying to display a changing variable
#2
the way you are doing the StringVar is correct. I suspect it is due to your root.after() condition?
import tkinter as tk
import random

root = tk.Tk()
L = tk.Label(root, justify = 'left')
L.pack()
V = tk.StringVar()
L['textvariable'] = V
V.set('Test')

def set_lbl():
	V.set(str(random.randint(0,100)))
	
btn = tk.Button(root, text='change', command=set_lbl).pack()

root.mainloop()
Recommended Tutorials:
Reply


Messages In This Thread
RE: Trying to display a changing variable - by metulburr - Aug-07-2017, 04:28 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  [Tkinter] Trying to display a variable in a label Jordansonatina 2 18,161 Oct-31-2019, 06:28 PM
Last Post: Jordansonatina
  Display and update the label text which display the serial value jenkins43 5 9,323 Feb-04-2019, 04:36 AM
Last Post: Larz60+
  Display more than one button in GUI to display MPU6000 Sensor readings barry76 4 4,068 Jan-05-2019, 01:48 PM
Last Post: wuf

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020