notebook.py :  » Web-Services » Shtoom » shtoom-0.2 » shtoom » ui » tkui » Python Open Source

Home
Python Open Source
1.3.1.2 Python
2.Ajax
3.Aspect Oriented
4.Blog
5.Build
6.Business Application
7.Chart Report
8.Content Management Systems
9.Cryptographic
10.Database
11.Development
12.Editor
13.Email
14.ERP
15.Game 2D 3D
16.GIS
17.GUI
18.IDE
19.Installer
20.IRC
21.Issue Tracker
22.Language Interface
23.Log
24.Math
25.Media Sound Audio
26.Mobile
27.Network
28.Parser
29.PDF
30.Project Management
31.RSS
32.Search
33.Security
34.Template Engines
35.Test
36.UML
37.USB Serial
38.Web Frameworks
39.Web Server
40.Web Services
41.Web Unit
42.Wiki
43.Windows
44.XML
Python Open Source » Web Services » Shtoom 
Shtoom » shtoom 0.2 » shtoom » ui » tkui » notebook.py
# file: notebook.py
# A simple notebook-like Tkinter widget.
# Copyright 2003, Iuri Wickert (iwickert yahoo.com)

from Tkinter import *

class notebook:
  # initialization. receives the master widget
  # reference and the notebook orientation
  def __init__(self, master, side=LEFT):
    
    self.active_fr = None
    self.count = 0
    self.choice = IntVar(0)

    # allows the TOP and BOTTOM
    # radiobuttons' positioning.
    if side in (TOP, BOTTOM):
      self.side = LEFT
    else:
      self.side = TOP

    # creates notebook's frames structure
    self.rb_fr = Frame(master, borderwidth=2, relief=RIDGE)
    self.rb_fr.pack(side=side, fill=X)
    self.screen_fr = Frame(master, borderwidth=2, relief=RIDGE)
    self.screen_fr.pack(fill=BOTH)
    

  # return a master frame reference for the external frames (screens)
  def __call__(self):

    return self.screen_fr

    
  # add a new frame (screen) to the (bottom/left of the) notebook
  def add_screen(self, fr, title):
    
    b = Radiobutton(self.rb_fr, text=title, indicatoron=0, \
      variable=self.choice, value=self.count, \
      command=lambda: self.display(fr))
    b.pack(fill=BOTH, side=self.side)
    
    # ensures the first frame will be
    # the first selected/enabled
    if not self.active_fr:
      fr.pack(fill=BOTH, expand=1)
      self.active_fr = fr

    self.count += 1
    
    
  # hides the former active frame and shows 
  # another one, keeping its reference
  def display(self, fr):
    
    self.active_fr.forget()
    fr.pack(fill=BOTH, expand=1)
    self.active_fr = fr

# END


def test():

    a = Tk()
    n = notebook(a, LEFT)

    # uses the notebook's frame
    f1 = Frame(n())
    b1 = Button(f1, text="Button 1")
    e1 = Entry(f1)
    # pack your widgets before adding the frame 
    # to the notebook (but not the frame itself)!
    b1.pack(fill=BOTH, expand=1)
    e1.pack(fill=BOTH, expand=1)

    f2 = Frame(n())
    b2 = Button(f2, text='Button 2')
    b3 = Button(f2, text='Beep 2', command=lambda:Tk.bell(a))
    b2.pack(fill=BOTH, expand=1)
    b3.pack(fill=BOTH, expand=1)

    f3 = Frame(n())

    n.add_screen(f1, "Screen 1")
    n.add_screen(f2, "Screen 2")
    n.add_screen(f3, "dummy")

    if __name__ == "__main__":
            a.mainloop()

    # END

if __name__ == "__main__":
    test()
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.