Python Forum
[Tkinter] Scale at the Top
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Tkinter] Scale at the Top
#1
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
Reply
#2

  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)))
Reply
#3
(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
Reply
#4
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)
Reply
#5
it works thanks
but why is it like that...it is a bug ?
i expect from_ = min ....to = max...to be the default... Dodgy
Reply
#6
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.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  How to instantly update the plot by getting values from a Scale widget? OLE 20 6,225 May-18-2022, 02:35 AM
Last Post: OLE
  [Tkinter] Resetting scale value back to 0 after the slider loses focus lwhistler 3 6,936 Mar-07-2017, 10:01 PM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020