title: Display variables values in a tkinter widget
body: <p>I am writing a program for interactive data fitting in python using Tkinter.
  I would like to:</p>
  
  <ol>
  <li><p>change the starting parameters (i.e. the guessing parameters) of the fitting curve manually form keyboard and plot the corresponding curve upon the experimental data in order to start the fitting procedure from a good point(ACHIEVED) </p></li>
  <li><p>display the actual value of the parameters in a widget as I change them by keyboard (NOT ACHIEVED)</p></li>
  </ol>
  
  <p>I've searched the net and I found some connections between my issue and Text widget or Entry widget..</p>
  
  <p>Do anyone have a good solution?</p>
  
  <p>here is the code modified as we're fitting a simple exponential, copy/paste run and try (use 'r','t','y','f','g','h' keys to modify params)..</p>
  
  <pre><code>import Tkinter as Tkinter
  from Tkinter import *
  from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg
  from matplotlib.figure import Figure
  from numpy import *  #exp,arange,sin,arctan,where
  import sys
  from scipy.optimize import leastsq
  
  class App:
  
  def __init__(self, master,slave,folnam,q_index,tab):
      # Create containers
      self.frame = Tkinter.Frame(master)
      self.frame2 = Tkinter.Text(slave,width=10,height=10)
      self.frame2.pack()
  
      self.q_index=q_index
  
      # Create buttons and bindings
      self.button_quit = Tkinter.Button(self.frame,text="QUIT", command=master.destroy)
      self.button_quit.pack(side="left")
      self.button_fit = Tkinter.Button(self.frame, text= 'fit!')
      self.button_fit.pack()
  
      self.frame.bind_all("&lt;Key&gt;", self.decrease_a,'+')    #################################
  
  
      # Fill with Data
      self.t = arange(1000)*.001
      self.data_to_fit = exp(-self.t)
      self.A=max(self.data_to_fit)-min(self.data_to_fit)
      self.B=min(self.data_to_fit)
  
      # Build Figure
      fig = Figure()
      self.ax = fig.add_subplot(111)
      self.ax.set_ylim( min(self.data_to_fit), max(self.data_to_fit) )      
      self.p = [self.A,self.B,.9,.5,10.,5.]
      self.line, = self.ax.plot(self.t[1:],abs(self.schultz(self.t[1:], 1., self.p)),'.-')   #tuple of a single element
      self.canvas = FigureCanvasTkAgg(fig,master=master)
      self.ax.plot(self.t[1:],self.data_to_fit[1:])
      self.canvas.show()
      self.canvas.get_tk_widget().pack(side='top', fill='both', expand=1)
      self.frame.pack()
  
  
  
  
  def schultz(self, t, q, p):
      Z=.1
      A, B, alpha, D, vm, sigma = p
      Z = ((sigma/vm)**-2)-1.
      Lambda = q*vm*t/(Z+1)
      g = ((Z+1)/(Z*q*vm*t))*sin(Z*arctan(Lambda))/(1+Lambda**2)**(Z/2.)
      where( abs(t)&gt;0., g, 1.)
      f = exp(-q**2*D*t)*((1.-alpha)+alpha*g)
      y = A*f+B
      return y
  
  
  
  
  def decrease_a(self,event):
  
    # Raise/lower amplitude with 'a', 'q' keys
      if event.char=='a':
          self.ax.get_ylim()          
          self.p[0]-= 1e10
          self.line.set_ydata(self.schultz(self.t[1:], 1, self.p))
          self.line.set_xdata(self.t[1:])           
          self.canvas.draw()  
      if event.char=='q':
          self.ax.get_ylim()          
          self.p[0]+=1e10
          self.line.set_ydata(self.schultz(self.t[1:], 1, self.p))
          self.line.set_xdata(self.t[1:])           
          self.canvas.draw()  
      # Raise/lower baseline with 's', 'w' keys
      if event.char=='s':
          self.ax.get_ylim()          
          self.p[1]-= 1e10
          self.line.set_ydata(self.schultz(self.t[1:], 1, self.p))
          self.line.set_xdata(self.t[1:])           
          self.canvas.draw()      
      if event.char=='w':
          self.ax.get_ylim()          
          self.p[1]+= 1e10
          self.line.set_ydata(self.schultz(self.t[1:], 1, self.p))
          self.line.set_xdata(self.t[1:])           
          self.canvas.draw()
      # Raise/lower alpha with 'd', 'e' keys
      if event.char=='d':
          self.ax.get_ylim()          
          self.p[2]-= .05
          self.line.set_ydata(self.schultz(self.t[1:], 1, self.p))
          self.line.set_xdata(self.t[1:])           
          self.canvas.draw()
      if event.char=='e':
          self.ax.get_ylim()          
          self.p[2]+= .05
          self.line.set_ydata(self.schultz(self.t[1:], 1, self.p))
          self.line.set_xdata(self.t[1:])           
          self.canvas.draw()
      # Raise/lower diffusion coefficient with 'f', 'r' keys
      if event.char=='f':
          self.ax.get_ylim()          
          self.p[3]-= .05
          self.line.set_ydata(self.schultz(self.t[1:], 1, self.p))
          self.line.set_xdata(self.t[1:])           
          self.canvas.draw()
      if event.char=='r':
          self.ax.get_ylim()          
          self.p[3]+= .05
          self.line.set_ydata(self.schultz(self.t[1:], 1, self.p))
          self.line.set_xdata(self.t[1:])           
          self.canvas.draw()
      # Raise/lower average speed with 'g', 't' keys
      if event.char=='g':
          self.ax.get_ylim()          
          self.p[2]-= .05
          self.line.set_ydata(self.schultz(self.t[1:], 1, self.p))
          self.line.set_xdata(self.t[1:])           
          self.canvas.draw()
  
      if event.char=='t':
          self.ax.get_ylim()          
          self.p[2]+= .05
          self.line.set_ydata(self.schultz(self.t[1:], 1, self.p))
          self.line.set_xdata(self.t[1:])           
          self.canvas.draw()
      # Raise/lower variance of speed distribution with 'h', 'y' keys
      if event.char=='h':
          self.ax.get_ylim()          
          self.p[2]-= .01
          self.line.set_ydata(self.schultz(self.t[1:], 1, self.p))
          self.line.set_xdata(self.t[1:])           
          self.canvas.draw()
      if event.char=='y':
          self.ax.get_ylim()          
          self.p[2]+= .01
          self.line.set_ydata(self.schultz(self.t[1:], 1, self.p))
          self.line.set_xdata(self.t[1:])           
          self.canvas.draw()
  
  root = Tkinter.Tk()
  root2 = Tkinter.Tk()
  app = App(root,root2,'/home/copo/Scrivania/correlazioni_da_fit',q_index=10, tab=False)
  
  root.mainloop()
  </code></pre>