Scaleとは
これです。
これはtkinter.Scaleです。
これはtkinter.ttk.Scaleです。 上のtkinter.Scaleの方が見やすいです。スクロール位置を数値表示しているので親切です。
Windowsではスライダーと言われています。なんかScaleではピンと来ないです。PythonのScrollbarはデータ値の設定はできないのでScaleを使います。
import tkinter as tk
def get_siler():
print(val.get())
if __name__ == '__main__':
root = tk.Tk()
root.title('Scale')
# スケールの作成
val = tk.DoubleVar()
sc = tk.Scale(
root,
variable=val,
orient=tk.HORIZONTAL,
length=200,
from_=0,
to=100,
relief= tk.FLAT,
command=lambda e: get_siler())
sc.grid(row=0, column=0, sticky=(tk.N, tk.E, tk.S, tk.W))
# Button
button = tk.Button(
root,
text='OK',
command=get_siler)
button.grid(row=0, column=1, padx=5, sticky=(tk.E))
root.mainloop()
relief= tk.FLATで形状を変えられます。 relief= tk.GROOVE
relief=
で形状を変えられます。 relief= tk.RAISED
relief= tk.RIDGE
relief= tk.SOLID
relief= tk.SUNKEN
あまり違いがわからないですね。
|