Josh Josh - 1 year ago 163
Python Question

How do I get tkinter scale widget to set it's upper limit to an updated variable?

I'm trying to set the 'to=' configuration option on a tkinter scale widget. I want to take the user input from an entry widget and use it as the upper limit on the scale.

The way I have it set up now, the scale just stays stuck at 0 after the user enters a value in the entry box and clicks the button. The 'to=' configuration option doesn't seem to update after the user changes the variable.

How do I get the scale widget to set it's upper limit to the new value?

Here's the code:

import tkinter

class HomePage:
def __init__(self):
self.root = tkinter.Tk()

self.entry_value = tkinter.IntVar()

self.entry_box = tkinter.Entry(master=self.root)

self.button = tkinter.Button(master=self.root, text='get value', command=self.set_value)


self.scale = tkinter.Scale(master=self.root, from_=0, to=self.entry_value.get(), orient='horizontal')

self.show_entry_value = tkinter.Button(self.root, text='Updated Value',
command=lambda: print(self.entry_value.get()))

def set_value(self):

app = HomePage()

Answer Source

Use the configure method to change the value:

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download