简体   繁体   中英

Linking a Tkinter slider to text entry

Hi I am currently trying to create a GUI in python using Tkinter. I was just wondering if there is a way to set the limits on a slider, based on an input into a text entry field. Below is the text entry I would like to link the slider to.

#tunnel height
self.height = Tkinter.StringVar()
self.height_entry = Tkinter.Entry(self,textvariable=self.height)
self.height_entry.grid(column=3,row=2,sticky='EW')
self.height_entry.bind("<Return>",self.OnPressEnter)
self.height.set("5.95")

self.height_label = Tkinter.StringVar()
label=Tkinter.Label(self,textvariable=self.height_label,
anchor="w",fg="white",bg="blue")
label.grid(column=3,row=3,columnspan=2,sticky='EW')
self.height_label.set("Sets the test section height")

I would like the upper limit of the slider to vary between 1, and the entry into the height box, but cannot find a way to do this.

Sorry if this has been asked before

You can change the parameters of the Scale using configure . Just put this into the method that's called when the input of the Entry is changed. Also, if you want a number, better use an IntVar .

var = IntVar()
text = Entry(root, textvariable=var)
scale = Scale(root, from_=0, to=100, orient='horizontal')
text.bind("<Return>", lambda event: scale.configure(to=var.get()))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM