Python Forum

Full Version: Scale at the Top
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello all,

i am a newbie in GUI/Tkinter. I was trying an example of Scale (from 4 to 50)from a book.
It works almost fine, however when i start the GUI, the scale is at the top showing '4'.
so to scale the letter 'A', i have to move the scale downwards.

Can someone please tell what is missing here ?

2.Question, what is that parameter "event" in the function setSize()...removing it create the following error :
"setSize() takes 1 positional argument but 2 were given"

i don't know how "Scale" uses the function "setSize"....

from tkinter import *

class Regler:
    def __init__(self):
        self.root = Tk()
        self.label = Label(self.root, text='A', font=('Arial',4))
        self.scale = Scale(self.root, length='3c', from_=4, to=50, command=self.setSize)

        self.label.pack(side = LEFT)
        self.scale.pack(side = RIGHT)
        self.root.mainloop()

    def setSize(self, event):
        x = int(self.scale.get())
        self.label.config(font=('Arial',x))

regler = Regler()
Thanks in advance

  1. If you want the scale to start at a different value use its set method
    self.scale.set(25)
  2. The event parameter is sent a string of the current value of the slider
        def setSize(self, event):
            x = int(self.scale.get())
            self.label.config(font=('Arial',x))
    can be changed to
        def setSize(self, event):
            self.label.config(font=('Arial',int(event)))
(Jul-20-2019, 11:49 AM)Yoriz Wrote: [ -> ]If you want the scale to start at a different value use its set method

good to know, but that won't solve my problem. my scale is from 4 to 50. And to go from 4 to 50 i have to scrole down (Top = 4, bottom = 50)... i want it to be opposite. i hope you understand what i mean
Switch the from_ & to values, then dragging the slider upwards will increase the value.

self.scale = Scale(self.root, length='3c', from_=50, to=4, command=self.setSize)
it works thanks
but why is it like that...it is a bug ?
i expect from_ = min ....to = max...to be the default... Dodgy
I guess the creator of tkinter thought someone would like the scale widget to be able to increase in value in both directions.
Its not a bug its a feature, just like you can make a range go up or down.