title: tkinter: manipulating variables inside tk.Label with textvariable
body: <p>I've just begun learning tkinter, and would like to know if it's possible to manipulate variables in <code>ttk.Label</code> on the fly with <code>textvariable=</code> or <code>text=</code>.  In order to demonstrate, behold my ingenious calculator program which multiplies two numbers and displays the product.:</p>
  
  <pre><code>from tkinter import *
  from tkinter import ttk
  
  root = Tk()
  root.title("Multiplier")
  
  mainframe = ttk.Frame(root, padding="3 3 12 12")
  mainframe.grid(column=0, row=0, sticky=(N, W, E, S))
  
  ## Calculation
  
  def multiply(*args):
      try:
         product.set(round(float(num1.get())*float(num2.get()),2))
      except ValueError:
          pass
  
  ## variables
  
  num1 = StringVar()
  num2 = StringVar()
  product = DoubleVar()
  
  ## first number
  
  ttk.Label(mainframe, text="First Number:").grid(column = 1, row = 1)
  num1_entry = ttk.Entry(mainframe, width=4, textvariable=num1)
  num1_entry.grid(column = 2, row = 1)
  num1_entry.bind('&lt;KeyPress&gt;', multiply)
  num1_entry.bind('&lt;KeyRelease&gt;', multiply)
  
  ## second number
  
  ttk.Label(mainframe, text="Second Number:").grid(column = 1, row = 2)
  num2_entry = ttk.Entry(mainframe, width=4, textvariable=num2)
  num2_entry.grid(column = 2, row = 2)
  num2_entry.bind('&lt;KeyPress&gt;',multiply)
  num2_entry.bind('&lt;KeyRelease&gt;',multiply)
  
  ## display results
  
  ttk.Label(mainframe, text = "Product:").grid(column = 1, row = 3)
  ttk.Label(mainframe, textvariable=product).grid(column = 2, row = 3)
  
  root.mainloop()
  </code></pre>
  
  <p>I can update the result whenever <code>product</code> is changed by using <code>textvariable=product</code>.  I can update <code>product</code> whenever <code>num1</code> or <code>num2</code> are changed by binding each to <code>&lt;KeyPress&gt;</code> and <code>&lt;KeyRelease&gt;</code>.  So far, so good.</p>
  
  <p>What I would like to know is whether it's possible to have another <code>ttk.Label</code> which displays my variable, but manipulated in some way.  Let's say I wanted to do something crazy like take my product and multiply it by 2.</p>
  
  <p>I know I could simply create a new variable:</p>
  
  <pre><code>newvariable = DoubleVar()
  </code></pre>
  
  <p>then update my <code>multiply</code> function thusly:</p>
  
  <pre><code>def multiply(*args):
      try:
         product.set(round(float(num1.get())*float(num2.get()),2))
         newvariable.set(round(product.get()*2),2))
      except ValueError:
          pass
  </code></pre>
  
  <p>and add my new label:</p>
  
  <pre><code>ttk.Label(mainframe, textvariable=newvariable).grid(column=1, row = 5)
  </code></pre>
  
  <p>That solves the problem nicely.  I have a new label that shows me my original product * 2, and is also updated on the fly as my entries are changed.  That's exactly what I want.</p>
  
  <p>In my actual project, however, I need to accomplish this many times over with different arguments.  It seems tedious to add a ton of new variables if I don't need to.</p>
  
  <p>What I'd like to be able to do is something like:</p>
  
  <pre><code>ttk.Label(mainframe, textvariable=product*2).grid(column=1, row = 5)
  </code></pre>
  
  <p>That gives me "TypeError: unsupported operand type(s) for *: 'DoubleVar' and 'int'.  I take that to mean that textvariable only wants 1 variable and does not want it manipulated.</p>
  
  <p>I also tried:</p>
  
  <pre><code>ttk.Label(mainframe, text=(product.get()*2)).grid(column=1, row = 5)
  </code></pre>
  
  <p>That one doesn't fail, but it also doesn't update automatically.  (That's the whole reason we need <code>textvariable</code> in the first place, right?)</p>
  
  <p>Is it even possible to do that without creating a new variable for each different instance where I want to manipulate my original variables?</p>
  
  <p>Thanks for any help!</p>