1

I'm making some program in tkinter and I got one problem.

In tkinter entry if I put 1 textvariable name in both of entry it will show instant on both of entries like this:

But I want to right entry immediately multiplied with 500. So If I put 2 on left it should show 1000 on right.

Label(frame2, foreground="#E3AAD5", text="500e").grid(row=0, column=0, sticky=W, padx=10) # Kreira label (opis kućice pokraj) 
    v_500 = IntVar()
    _500 = Entry(frame2, textvariable=v_500)
    _500.grid(row=0, column=1, sticky=W)

    Entry(frame2, textvariable=v_500*500).grid(row=0, column=2, sticky=W)

But it doesn't work.

2
  • TypeError: unsupported operand type(s) for *: 'instance' and 'int' Commented Aug 21, 2015 at 11:58
  • I think you have to use validatecommand Commented Aug 21, 2015 at 12:16

1 Answer 1

2

There is no direct support for what you want. That being said, what you want to do is fairly easy. IntVars can be configured to call a function when they change. You can use this callback to do the multiplication and update the widget.

For example:

def update_other_label(name1, name2, mode):
    value = v_500.get()
    product = value * 500
    v_500_mult.set(product)

v_500 = IntVar()
v_500.trace("w", update_other_label)
v_500_mult = Intvar()
...
_500 = Entry(frame2, textvariable=v_500)
Entry(frame2, textvariable=v_500_mult).grid(row=0, column=2, sticky=W)

You don't have to use an IntVar for the second entry if you don't want -- you can directly modify the entry widget if you keep a reference. I didn't do it that way since you aren't keeping a reference.

Sign up to request clarification or add additional context in comments.

2 Comments

@CheckThisOut: that's what Tkinter requires. It allows you to use the same callback for multiple variables and modes, and to know which variable and which mode triggered the callback.
Okay, thank you. But what If I have more variables for multiply, not only 500. I need to multiply 10 variables with 1 definition. I don't want to mess up with vars cuz it's program for counting.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.