#! /usr/bin/env python

"""
button.py 

This demonstration script creates a toplevel window containing
several button widgets.

June 14, 2005
"""


import Tkinter as Tk
import template as A


class Button(Tk.Button):
    """ Buttons to change bg of frames """
    def __init__(self, master, obj, color_name, color_id):
        Tk.Button.__init__(self, master, text=color_name, width=15, command=self.command)
        self.obj = obj
        self.color_id = color_id

    def command(self):
        self.obj.demo_frame.config(bg=self.color_id)
#        self.obj.demo_buttons.config(bg=self.color_id)
        

#########################################
# class Demo(A.Demo):
#     """a demo class """
#     
#     def __init__(self, cmain):
#         A.Demo.__init__(self, cmain, __file__)
#         self.ini_frame()
# 
#     def ini_demo_called(self):
#         """ This method should be defined"""
#         self.ini_demo_called_0()
#         self.ini_frame()
# 
#     def ini_frame(self):
#########################################
class Frame(Tk.Frame):
    def __init__(self, master=None):
        Tk.Frame.__init__(self, master)
#        self.demo_main_frame.master.title("Button Demonstration")
#        self.demo_main_frame.master.geometry('+50+50')
        self.master.title("Button Demonstration")
        self.master.geometry('+50+50')
        self.demo_frame=Tk.Frame(self)
        self.demo_frame.pack(side=Tk.BOTTOM, fill=Tk.BOTH, expand=1)
        label = Tk.Label(self, text=
        "If you click on any of the four buttons below, " 
        "the background of the button area will change to the color indicated in the button."
        , width=35, wraplength='8c', font=('Helvetica', '14'), justify=Tk.LEFT)
        label.pack()
        for name, code in [('Deeppink', '#FF1493'), ('Cornflowerblue', '#6495ED'),
                             ('Springgreen', '#00FF7F'), ('Gold', '#FFD700')]:
            b = Button(self.demo_frame, self, name, code) 
            b.pack(padx=10, pady=5)


##------------------------------------------------ 

if __name__ == '__main__':
    f = Frame()
    f.pack()
    f.mainloop()