How to increase the size of the ttk.Scale handle/button #220
-
|
I'm developing a touch-screen based app, and using the I've tried the solution outlined in this issue, which involves setting scaling for high-dpi awareness ( I'm wondering if anyone has any ideas for how to increase the size of the handle/button in the Many thanks, |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
|
There isn't a way to isolate the handle image resize. You could create your own layout for the scale, which is essentially what I did below. I copied and modified the code I use in the style builder. This demo shows a gigantic slider handle. import ttkbootstrap as ttk
from ttkbootstrap.constants import *
def create_custom_scale_style(style_obj, style_name, handle_size, colorname=DEFAULT):
"""Create a style for the ttk.Scale widget.
Parameters:
colorname (str):
The color label used to style the widget.
"""
builder = style_obj._get_builder()
images = builder.create_scale_assets(size=handle_size)
STYLE = "TScale"
if any([colorname == DEFAULT, colorname == ""]):
h_ttkstyle = f"Horizontal.{STYLE}"
v_ttkstyle = f"Vertical.{STYLE}"
else:
h_ttkstyle = f"{style_name}.Horizontal.{STYLE}"
v_ttkstyle = f"{style_name}.Vertical.{STYLE}"
# ( normal, pressed, hover, disabled, htrack, vtrack )
images = builder.create_scale_assets(colorname, handle_size)
# horizontal scale
h_element = h_ttkstyle.replace(".TS", ".S")
style_obj.element_create(
f"{h_element}.slider",
"image",
images[0],
("disabled", images[3]),
("pressed", images[1]),
("hover", images[2]),
)
style_obj.element_create(f"{h_element}.track", "image", images[4])
style_obj.layout(
h_ttkstyle,
[
(
f"{h_element}.focus",
{
"expand": "1",
"sticky": NSEW,
"children": [
(f"{h_element}.track", {"sticky": EW}),
(
f"{h_element}.slider",
{"side": LEFT, "sticky": ""},
),
],
},
)
],
)
# vertical scale
v_element = v_ttkstyle.replace(".TS", ".S")
style_obj.element_create(
f"{v_element}.slider",
"image",
images[0],
("disabled", images[3]),
("pressed", images[1]),
("hover", images[2]),
)
style_obj.element_create(f"{v_element}.track", "image", images[5])
style_obj.layout(
v_ttkstyle,
[
(
f"{v_element}.focus",
{
"expand": "1",
"sticky": NSEW,
"children": [
(f"{v_element}.track", {"sticky": NS}),
(
f"{v_element}.slider",
{"side": TOP, "sticky": ""},
),
],
},
)
],
)
# register ttkstyles
style_obj._register_ttkstyle(h_ttkstyle)
style_obj._register_ttkstyle(v_ttkstyle)
if __name__ == '__main__':
app = ttk.Window(themename='superhero')
create_custom_scale_style(app.style, 'custom', 50)
scale = ttk.Scale(style='custom.Horizontal.TScale')
scale.pack(fill=X, expand=YES)
app.mainloop() |
Beta Was this translation helpful? Give feedback.

There isn't a way to isolate the handle image resize. You could create your own layout for the scale, which is essentially what I did below. I copied and modified the code I use in the style builder. This demo shows a gigantic slider handle.