Can't apply style to Tkinter slider

338 Views Asked by At

I'm trying to apply a style to a slider widget in tkinter. However, the changes to slider_style parameters on the code below don't affect my_slider. Specifically, I'm trying to change the trough width to something smaller. I have seen on different tutorials that either the width or the sliderthickness parameters might do the trick, but I had no luck with either (or with any other style parameter, for that matter). Here is the relevant code:

from tkinter import *
import tkinter.ttk as ttk

window_width = 1000
window_height = 100
root = Tk()
root.title('Measure Marker')
root.geometry(f'{window_width}x{window_height}')

slider_style = ttk.Style()
slider_style.configure('SliderStyle.Horizontal.TScale', width=5, sliderthickness =5)
my_slider = ttk.Scale(root, from_=0, to=100, length=900, style='SliderStyle.Horizontal.TScale')
my_slider.pack(pady=30)

root.mainloop()

Am I applying SliderStyle correctly? Is that the way to go to change the trough width?

1

There are 1 best solutions below

8
On

I tried to do this a while ago, this works I literally just tested it,

from tkinter import *

def sel():
   selection = "Value = " + str(var.get())
   label.config(text = selection)

window_width = 1000
window_height = 100
root = Tk()
root.geometry(f'{window_width}x{window_height}')

var = DoubleVar()
scale = Scale(root, width=5, orient=HORIZONTAL, variable = var )
scale.pack(anchor=CENTER)

button = Button(root, text="Get Scale Value", command=sel)
button.pack(anchor=CENTER)

label = Label(root)
label.pack()

root.mainloop()