Define GUI in a class : UI Class « GUI Tk « Python






Define GUI in a class

Define GUI in a class

from Tkinter import *

class GUI:
    def __init__(self):
     self.root = Tk()
        self.root.title('Frame Styles')
        for bdw in range(5):
            setattr(self, 'of%d' % bdw, Frame(self.root, borderwidth=0))
            Label(getattr(self, 'of%d' % bdw),
                  text='borderwidth = %d  ' % bdw).pack(side=LEFT)
            ifx = 0
            for relief in [RAISED, SUNKEN, FLAT, RIDGE, GROOVE, SOLID]:
                setattr(self, 'f%d' % ifx, Frame(getattr(self, 'of%d' % bdw),
                                                 borderwidth=bdw, relief=relief))
                Label(getattr(self, 'f%d' % ifx), text=relief, width=10).pack(side=LEFT)
                getattr(self, 'f%d' % ifx).pack(side=LEFT, padx=7-bdw, pady=5+bdw)        
                ifx = ifx+1
            getattr(self, 'of%d' % bdw).pack()        

myGUI = GUI()
myGUI.root.mainloop()


           
       








Related examples in the same category

1.Demonstrates using a class with TkinterDemonstrates using a class with Tkinter
2.Using A Class Structure to define GUIUsing A Class Structure to define GUI
3.Creating a simple dialogCreating a simple dialog
4.Button action inside a classButton action inside a class
5.Define class to handle GUI components
6.Subclasses buttonSubclasses button
7.Subclass HelloButton: redefine press-handler methodSubclass HelloButton: redefine press-handler method
8.Sub class button: add callback method and pack myselfSub class button: add callback method and pack myself
9.Sub class button: add callback method and use a real dictionary
10.subclasses frame: attach widgets to selfsubclasses frame: attach widgets to self
11.Subclass Frame and use itSubclass Frame and use it
12.Use Frame subclassUse Frame subclass
13.Redefine call method in GUI subclassRedefine call method in GUI subclass
14.Standalone container class