May-31-2017, 03:03 AM
You need to use textvariable
You need to change your structure in how you are doing things. For example you are creating a new label every time you callback, instead just make the one label, and set it in the callback. Also you should really consider using classes (OOP).
Here is a small example using textvariable. Keep pressing the button and the label changes based on the current epoch timestamp.
You need to change your structure in how you are doing things. For example you are creating a new label every time you callback, instead just make the one label, and set it in the callback. Also you should really consider using classes (OOP).
Here is a small example using textvariable. Keep pressing the button and the label changes based on the current epoch timestamp.
import tkinter as tk import time def callback(): lbl.set('{}'.format(time.time())) root = tk.Tk() lbl = tk.StringVar() lbl.set('default') tk.Label(root, textvariable=lbl).pack() tk.Button(root, text="Get Time", command=callback).pack() root.mainloop()
Recommended Tutorials: