Scale

tkinter에는 슬라이드 바인 scale 위젯이 존재한다.

def DrawScale(self):
    scale = tkinter.Scale(self.frame, orient="horizontal", showvalue=True, from_=100, to=0, command=self.CallScale())
    scale.grid(row=0, column=0)

 

 

Scale과 함수 연동

scale의 바가 움직일 때마다 CallScale 함수가 호출된다.

def DrawScale(self):
    scale = tkinter.Scale(self.frame, orient="horizontal", showvalue=True, from_=100, to=0, command=self.CallScale())
    scale.grid(row=0, column=0)

def CallScale(self):
    print('CallScale')

 

 

CallScale 함수에서 scale 값 출력

def DrawScale(self):
    scale = tkinter.Scale(self.frame, orient="horizontal", showvalue=True, from_=100, to=0, command=lambda value: self.CallScale(value))
    scale.grid(row=0, column=0)

def CallScale(self, value):
    print(value)

 

 

전체코드

 

GitHub - HydroponicGlass/2022_Example_Tkinter

Contribute to HydroponicGlass/2022_Example_Tkinter development by creating an account on GitHub.

github.com

import tkinter

class ScaleExample:
    def __init__(self, frame):
        self.frame = frame
    
    def DrawScale(self):
        scale = tkinter.Scale(self.frame, orient="horizontal", showvalue=True, from_=100, to=0, command=lambda value: self.CallScale(value))
        scale.grid(row=0, column=0)

    def CallScale(self, value):
        print(value)

def main():
    main_window = tkinter.Tk()      
    main_window.title('scaleExample')
    main_window.geometry('200x200+0+0') # windows size : width, heigth, x, y
    main_window.resizable(False, False) # window scale enable : Updown, LeftRight
    scaleExample = ScaleExample(main_window)
    scaleExample.DrawScale()
    main_window.mainloop()

if __name__ == '__main__':
    main()