By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
464,706 Members | 1,298 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 464,706 IT Pros & Developers. It's quick & easy.

Tkinter: visualizing parameters in real time

P: 1
Hi, I'm writing an interactive program to fit some data quickly.
I would like to keep an eye on the actual value of the parameters of the fitting function which i plot on the same graph f the data while changing by <Key> binding the parameters value..
I was thinking about using multiple textbox but I'm not used yet to their syntax..
Is that an appropriate way of resolving this issue and if yes i could i work it out?
Is there any other better way of facing the problem?
Aug 13 '12 #1
Share this Question
Share on Google+
1 Reply

Expert 100+
P: 626
Use a StringVar() or IntVar() in any container you choose, listbox, labels, etc. When you change it, the new value is displayed where ever it is displayed, so to update =
string_var_1.set("new value")

The following program changes the value in the Entry box. The same StringVar() is also displayed in the middle label on the top. It changes as the value in the entry box changes. The IntVar() is incremented by clicking the button.
Expand|Select|Wrap|Line Numbers
  1. import Tkinter
  2.  
  3. class EntryTest:
  4.    """ shows using the same StringVar in the second list box
  5.        and in the entry box
  6.    """
  7.    def __init__(self):
  8.       self.top = Tkinter.Tk()
  9.       self.top.title("Test of Entry")
  10.       self.top.geometry("200x150+10+10")
  11.  
  12.       self.str_1 = Tkinter.StringVar()
  13.       label_lit = Tkinter.StringVar()
  14.       self.int_lit = Tkinter.IntVar()
  15.       self.int_ctr = 0
  16.  
  17.       label_1 = Tkinter.Label(self.top, textvariable = label_lit )
  18.       label_1.pack()
  19.       label_lit.set( "Test of Label")
  20.  
  21.       Tkinter.Label(self.top, textvariable = self.str_1 ).pack()
  22.  
  23.       Tkinter.Label(self.top, textvariable = self.int_lit ).pack()
  24.       self.int_lit.set(self.int_ctr)
  25.  
  26.       self.entry_1=Tkinter.Entry(self.top, textvariable=self.str_1)
  27.       self.entry_1.pack()
  28.       self.str_1.set( "Entry Initial Value" )
  29.  
  30.       print_button = Tkinter.Button(self.top, text='INCREMENT INT VAR',
  31.                      command=self.getit, bg='blue', fg='white' )
  32.       print_button.pack(fill=Tkinter.X, expand=1)
  33.  
  34.       exit_button= Tkinter.Button(self.top, {"text":'EXIT',
  35.                    "command":self.top.quit, "bg":'red', "fg":'white'} )
  36.       exit_button.pack(fill=Tkinter.X, expand=1)
  37.  
  38.       self.entry_1.focus_set()
  39.  
  40.       self.top.mainloop()
  41.  
  42.    ##-----------------------------------------------------------------
  43.    def getit(self) :
  44.       self.int_ctr += 1
  45.       self.int_lit.set(self.int_ctr)
  46.  
  47.  
  48. ##===============================================================
  49. if "__main__" == __name__  :
  50.    ET=EntryTest()
  51.    print "under __main__ =", ET.str_1.get() 
Aug 13 '12 #2

Post your reply

Sign in to post your reply or Sign up for a free account.