Closed OlegXio closed 2 months ago
Sadly, the ttk scale widget does not have the same customization as the tk version. However, we can work around this using a function like you suggest, here is an example:
import TKinterModernThemes as TKMT
import tkinter as tk
class App(TKMT.ThemedTKinterFrame):
def __init__(self, theme, mode, usecommandlineargs=True, usethemeconfigfile=True):
super().__init__("Image", theme, mode, usecommandlineargs=usecommandlineargs,
useconfigfile=usethemeconfigfile)
self.password_length = tk.IntVar(value=25)
self.output = tk.StringVar(value="25")
self.frame = self.addLabelFrame("Frame")
self.frame.Scale(0, 100, self.password_length, widgetkwargs={"command": self.handle_update})
self.pswlenght = self.frame.Text("", widgetkwargs={"textvariable":self.output})
self.run()
def handle_update(self, val):
self.output.set(str(round(float(val))))
if __name__ == "__main__":
App("park", "dark")
In the above code snippet, you can see that a variable of Int type is set for the slider, but when we try to print it, we get a value of float type. We could set text=int(password_lenght.get()) instead of textvariable for ttk.Label, but this is not an updatable function. It could be updated if Scale had the ability to set the attribute command=updatescale_handler.
When trying to use StringVar, DoubleVar instead of IntVar the identical situation occurs (despite the fact that the Scale widget should accept only IntVar or DoubleVar in variable: