Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>If the question is: "How do you update a Label widget?"<br> then the answer is with the widget's <code>configure</code> method.</p> <pre><code># Tkinter in Python 2.7 &amp; tkinter in 3.2 import Tkinter as tk class GUI(tk.Tk): def __init__(self): tk.Tk.__init__(self) bF = tk.Frame(self, bd=8, relief='sunken') bF.pack(expand='true', fill='x') changeButton = tk.Button(bF, text='Change', bd=4, fg='white', relief='groove', activebackground='green', command=self.change_label) changeButton.pack() self.entryLabel = tk.Label(self, text='Hello') self.entryLabel.pack() self.mEntry = tk.Entry(self, bd=4, relief='sunken') self.mEntry.pack() def change_label(self): data = self.mEntry.get() self.entryLabel.configure(text=data) gui = GUI() gui.mainloop() </code></pre> <p>You will want to make your GUI a class like in this example;<br> that way you can use the self. prefix to refer to the widget made in another method.</p> <p>In your example it looks like you might be saying 'mt' is a <a href="http://infohost.nmt.edu/tcc/help/pubs/tkinter/control-variables.html" rel="nofollow">control variable</a>.<br> The answer would still be to make a class, so that you can use the self. prefix.</p> <p>The control variable likely isn't necessary unless you would want<br> the label to be updated as you changed the contents of the Entry widget:</p> <pre><code>import Tkinter as tk class GUI(tk.Tk): def __init__(self): tk.Tk.__init__(self) bF = tk.Frame(self, bd=8, relief='sunken') bF.pack(expand='true', fill='x') var = tk.StringVar() var.set('Hello') entryLabel = tk.Label(self, textvariable=var) entryLabel.pack() mEntry = tk.Entry(self, bd=4, relief='sunken', textvariable=var) mEntry.pack() gui = GUI() gui.mainloop() </code></pre>
 

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