python - Entry widget contents not changing with function call -
i need change content of entry whenever tkinter frame shown. below have far, , doesn't seem work. have tried use data = self.read()
, now.insert(0, data)
, has not worked either. if value displayed doesn't changed every time class readlabel1
called.
class readlabel1(tk.frame): def __init__(self, parent, controller): tk.frame.__init__(self, parent, bg="blue") label = tk.label(self, text="somedata:", font = "times 12", bg="blue") label.place(x=10, y=100) #ack(pady=5,padx=30) self.smstr = tk.stringvar() now=tk.entry(self, width=22, textvariable=self.read()) now.place(x=120, y=103) def read(self): # code data return data
you need turn 'change content of entry' 1 parameter callback, turn 'whenever tkinter frame shown' event, , bind app, event, , callback. here minimal example.
import time import tkinter tk root = tk.tk() = tk.stringvar() lab = tk.label(root, textvariable=now) lab.pack() def display_now(event): now.set(time.ctime()) root.bind('<visibility>', display_now) root.bind('<focusin>', display_now)
minimizing window icon , bringing triggers visibility event. covering , merely uncovering different window did not, @ least not windows. clicking on uncovered, or merely inactivated, window triggered focusin. can experiment more system. used tkinter reference
Comments
Post a Comment