# L-32 MCS 260 Fri 3 Apr 2015 : exscale2.py

"""
The third example of a scale uses the command
argument in the scale widget and does not need
the value button.
"""

from tkinter import Tk, DoubleVar, Scale
from tkinter import Entry, END, INSERT

class ShowScale(object):
    """
    GUI to demonstrate use of a scale.
    """
    def __init__(self, wdw):
        """
        determines the layout of the GUI
        """
        wdw.title('example of a scale')
        self.low = 0.0
        self.high = 1.0
        self.var = DoubleVar()
        self.scl = Scale(wdw, \
            orient='horizontal', \
            from_=self.low, to=self.high, \
            tickinterval=(self.high-self.low)/5.0, \
            resolution=(self.high-self.low)/1000.0, \
            length=300, variable=self.var, \
            command=self.show_value)
        self.scl.grid(row=0, column=0)
        self.ent = Entry(wdw)
        self.ent.grid(row=1, column=0)

    def show_value(self, val):
        """
        Displays the value of the scale variable
        in the entry widget.
        """
        self.ent.delete(0, END)
        strval = 'value = ' + str(val)
        self.ent.insert(INSERT, strval)

def main():
    """
    Instantiates the GUI and
    launches the main event loop.
    """
    top = Tk()
    show = ShowScale(top)
    top.mainloop()

if __name__ == "__main__":
    main()
