outlook bar like widget

Mohammad Tayseer m_tayseer82 at yahoo.com
Wed Feb 21 10:09:47 EST 2007


This is a module that does what you want using Tkinter

----------------
from Tkinter import *

class OutlookBar(Frame):
    def __init__(self, *args, **options):
        Frame.__init__(self, *args, **options)
        self.panes = {}
        
    def add_pane(self, name, pane):
        self.panes[name] = pane
        pane.pack(side=TOP, fill=X)
        
    def get_frame(self, name):
        return self.panes[name]
        
class OutlookPane(Frame):
    def __init__(self, *args, **options):
        if options.get('text'):
            text = options['text']
            del options['text']
            
        Frame.__init__(self, *args, **options)
        self.btn = Button(self, text=text, command=self.toggle_collapse)
        self.btn.pack(side=TOP, fill=X)
        self.child_frame = Frame(self)
        self.child_frame.pack(side=TOP, fill=X)
        if options.get('collapsed'):
            self.collapsed = True
            del options['collapsed']
        else:
            self.collapsed = False
            self.child_frame.pack(side=TOP, fill=X)
            
    def frame(self):
        return self.child_frame
        
    def toggle_collapse(self):
        if self.collapsed:
            self.child_frame.pack(side=TOP) # show
        else:
            self.child_frame.pack_forget()
        self.collapsed = not self.collapsed
        
    def add_widget(self, widget):
        widget.pack(side=TOP)
if __name__ == '__main__':
    root = Tk()
    root.title('Outlook Bar Demo')
    bar = OutlookBar(root)
    bar.pack(expand=1, fill=BOTH)
    bar.add_pane('pane1', OutlookPane(bar, text='Hello'))
    pane1 = bar.get_frame('pane1')
    pane1.add_widget(Button(pane1.frame(), text='Button 1'))
    pane1.add_widget(Button(pane1.frame(), text='Button 2'))
    pane1.add_widget(Button(pane1.frame(), text='Button 3'))

    bar.add_pane('pane2', OutlookPane(bar, text='Zankalon'))
    pane2 = bar.get_frame('pane2')
    pane2.add_widget(Button(pane2.frame(), text='Button 1'))
    pane2.add_widget(Button(pane2.frame(), text='Button 2'))
    pane2.add_widget(Button(pane2.frame(), text='Button 3'))

    mainloop()
----------------


 
---------------------------------
The fish are biting.
 Get more visitors on your site using Yahoo! Search Marketing.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20070221/ea5a3c3f/attachment.html>


More information about the Python-list mailing list