# L-32 MCS 260 Fri 3 Apr 2015 : exscale1.py
"""
Second example of a scale uses a class.
The benefit of the class is the separation
of the layout (object data attributes)
from the actions (functional attributes).
"""
from tkinter import Tk, DoubleVar, Scale
from tkinter import Entry, END, INSERT, Button

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)
        self.scl.grid(row=0, columnspan=2)
        self.ent = Entry(wdw)
        self.ent.grid(row=1, column=0)
        self.btt = Button(wdw, text="show value", \
            command=self.show_value)
        self.btt.grid(row=1, column=1)

    def show_value(self):
        """
        Shows the value of the scale variable
        in the entry widget.
        """
        self.ent.delete(0, END)
        self.ent.insert(INSERT, self.var.get())

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

if __name__ == "__main__":
    main()
