Tkinter: visualizing parameters in real time

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • copo
    New Member
    • Aug 2012
    • 1

    Tkinter: visualizing parameters in real time

    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?
  • dwblas
    Recognized Expert Contributor
    • May 2008
    • 626

    #2
    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.se t("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.
    Code:
    import Tkinter
    
    class EntryTest:
       """ shows using the same StringVar in the second list box
           and in the entry box
       """
       def __init__(self):
          self.top = Tkinter.Tk()
          self.top.title("Test of Entry")
          self.top.geometry("200x150+10+10")
    
          self.str_1 = Tkinter.StringVar()
          label_lit = Tkinter.StringVar()
          self.int_lit = Tkinter.IntVar()
          self.int_ctr = 0
    
          label_1 = Tkinter.Label(self.top, textvariable = label_lit )
          label_1.pack()
          label_lit.set( "Test of Label")
    
          Tkinter.Label(self.top, textvariable = self.str_1 ).pack()
    
          Tkinter.Label(self.top, textvariable = self.int_lit ).pack()
          self.int_lit.set(self.int_ctr)
    
          self.entry_1=Tkinter.Entry(self.top, textvariable=self.str_1)
          self.entry_1.pack()
          self.str_1.set( "Entry Initial Value" )
    
          print_button = Tkinter.Button(self.top, text='INCREMENT INT VAR',
                         command=self.getit, bg='blue', fg='white' )
          print_button.pack(fill=Tkinter.X, expand=1)
    
          exit_button= Tkinter.Button(self.top, {"text":'EXIT',
                       "command":self.top.quit, "bg":'red', "fg":'white'} )
          exit_button.pack(fill=Tkinter.X, expand=1)
    
          self.entry_1.focus_set()
    
          self.top.mainloop()
    
       ##-----------------------------------------------------------------
       def getit(self) :
          self.int_ctr += 1
          self.int_lit.set(self.int_ctr)
    
    
    ##===============================================================
    if "__main__" == __name__  :
       ET=EntryTest()
       print "under __main__ =", ET.str_1.get()

    Comment

    Working...