Note that there are some explanatory texts on larger screens.

plurals
  1. PORefreshing tk window with a button
    primarykey
    data
    text
    <p>I would like to refresh tk window when I push a button, but I have been striking out. Help would be appreciated. Below is what I have tried. I would like the tk.Label line to update when I change the input box and hit refresh, but it isn't happening.</p> <pre><code>import Tkinter as tk class MAIN(object): def __init__(self, master, **kwargs): frame = tk.Frame(master, borderwidth=5) frame.grid() et1 = tk.Entry(frame) et1.insert(0, '10') et1.grid(row=0,column=0,sticky=tk.W) tk.Label(frame, text = et1.get()).grid(row=1, column=0, sticky=tk.W) refresh = tk.Button(frame, text='Refresh', command = frame.update()) refresh.grid(row=2, column=0, sticky=tk.W) root=tk.Tk() app=MAIN(root) root.mainloop() </code></pre> <p>Any Help would be greatly appreciated. Thanks</p> <p>Edit:</p> <p>I have also tried to use the update_idletasks(), but that didn't work either.</p> <p>Answer from sc0tt's help:</p> <pre><code>import Tkinter as tk class MAIN(object): def __init__(self, master, **kwargs): frame = tk.Frame(master, borderwidth=5) frame.grid() self.et1 = tk.Entry(frame) self.et1.insert(0, 10) self.et1.grid(row=0,column=0,sticky=tk.W) self.label_contents = tk.StringVar() self.label_contents.set(self.et1.get()) tk.Label(frame, textvariable=self.label_contents).grid(row=1, column=0, sticky=tk.W) refresh = tk.Button(frame, text='Refresh', command = self.refresh_hit) refresh.grid(row=2, column=0, sticky=tk.W) def refresh_hit(self): self.label_contents.set(self.et1.get()) root=tk.Tk() app=MAIN(root) root.mainloop() </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload