Home > Back-end >  How to make python Tkinter volume slider in a professional way
How to make python Tkinter volume slider in a professional way

Time:05-28

I'm trying to make a volume controller in python tkinter. But what exactly the problem is that, I want to make it look rich and professional. So when I tried using tkinter scale widget, it worked. But the widget is just a normal one. I wanted to know a way to make it look like the image below I have sent.

Volume Slider

My current one's code is this:

def slider(self):
        self.scale = scale = ttk.Scale(self.canvas, from_=0, to=100, orient=HORIZONTAL)
        print(self.scale.winfo_class())
        self.scale.place(x=580,y=455)
        self.scale.set(70)

Is there anyway I can make it look better like the one in the Image?

What all things I want is:

  • A knob like round thing like in the image which is movable
  • Some color should fill in the area that is already covered.
  • A pop up or anything to show the current details of the volume.


I'm using pygame to play music in tkinter btw.. If this isn't possible, please suggest me a better way/alternative to do this. Thank you.

CodePudding user response:

As far as I know, there is no existing widget with a look exactly like what you are asking for. However, tkinter provides a way to craft your own widget styles, which might make it possible to do what you want.

Tkinter comes with a module named ttk, which stands for "themed tk". It allows you to define custom styles for individual widgets, and to bundle those styles into a collection known as a theme. If you want to create a widget with a custom look, you can use this module to do so.

Unfortunately, being able to design a custom theme for a widget isn't very well documented. The best documentation I personally know of is on tkdocs.com, in the section Styles and Themes. It gives a pretty good rundown of the terminology and overall description of how themes work. The python documentation for ttk also gives some additional information about creating styles and layouts in a section titled Ttk Styling.

For inspiration, you can check out the code for the ttkthemes project (github, public documentation) which has many different themes that you can examine. I doubt there is one exactly like you want, but you should be able to create your own after looking through the examples.

CodePudding user response:

It is as easy as setting a theme for the TkInter project. Done in Python it looks like that:

s.theme_use('themename')

You might benefit from reading Styles and Themes documentation of TkDocs.

  • Related