Comparing ttk tkinter Scales#
Compare the Scales#
Note that tkinter can show a description, slider value and range of values
First of all create scales in tkinter and ttk and compare what is available using standard attributes and see what is available in ttk Style. Refer to "Tkinter 8.5 reference a GUI for Python" table 30. Scale Widget Options for the tkinter Scale and table 57. ttk.Scale Options and table 58, tkinter Scale options not in ttk.Scale. The last table shows which options are not supported and may need to be thought about, see following table To be Coded.
Table: Attributes for tkinter and ttk Scales
Attributes in Original |
Attributes in ttk |
ttk Style |
To be Coded |
Another Widget |
|---|---|---|---|---|
activebackground |
√ |
|||
background |
√ |
|||
borderwidth |
√ |
|||
class |
||||
command |
command |
|||
cursor |
cursor |
|||
digits |
√ |
|||
font |
√ |
|||
foreground |
√ |
|||
from_ |
from_ |
|||
highlightbackground |
√ |
|||
highlightcolor |
√ |
|||
highlightthickness |
√ |
|||
label |
√ |
|||
length |
length |
|||
orient |
orient |
|||
relief |
√ |
|||
repeatdelay |
||||
repeatinterval |
||||
resolution |
√ |
|||
showvalue |
√ |
|||
sliderlength |
√ |
|||
sliderrelief |
√ |
|||
state |
√ |
|||
takefocus |
√ |
|||
tickinterval |
takefocus |
|||
to |
to |
|||
troughcolor |
√ |
|||
variable |
variable |
|||
width |
√ |
Warning
Not all ttk Scale widgets react as expected or in the same way when querying or setting when using Style.
Table: Methods used in tkinter and ttk Scales
Common Methods ttk Widgets |
Special ttk Scale |
Original Scale |
|---|---|---|
.cget() |
||
.configure() |
||
.coords() |
||
.get() |
||
identify(x,y) |
identify(x,y) |
|
.instate() |
||
.set() |
Show/Hide Code 01ttk_tkinter.py
import tkinter as tk
import tkinter.ttk as ttk
root = tk.Tk()
s = ttk.Style()
s.theme_use('default')
sch = tk.Scale(root, from_=-1.0, to=1.0, label='Bogusstuinuous', orient='horizontal',
resolution=0.02, showvalue=1, tickinterval=0.5, digits=3,
length=200)
sch.grid()
scv = tk.Scale(root, from_=-0, to=10, label='Fun', orient='vertical',
resolution=1, showvalue=1, tickinterval=2,
length=200)
scv.grid(row=0, column=1)
sep = ttk.Separator(root, orient='horizontal')
sep.grid(row=1, column=0, columnspan=2)
scth = ttk.Scale(root, from_=-1.0, to=1.0, length=200)
scth.grid(row=2, column=0)
sctv = ttk.Scale(root, from_=0, to=10, length=200, orient='vertical')
sctv.grid(row=2, column=1)
root.mainloop()