MCPcopy Create free account
hub / github.com/ActiveState/code / Notebook

Class Notebook

recipes/Python/541092_tkNotebook/recipe-541092.py:39–130  ·  view source on GitHub ↗

Notebook Widget

Source from the content-addressed store, hash-verified

37from Tkinter import *
38
39class Notebook(Frame):
40 """Notebook Widget"""
41 def __init__(self, parent, activerelief = RAISED, inactiverelief = RIDGE, xpad = 4, ypad = 6, activefg = 'black', inactivefg = 'black', **kw):
42 """Construct a Notebook Widget
43
44 Notebook(self, parent, activerelief = RAISED, inactiverelief = RIDGE, xpad = 4, ypad = 6, activefg = 'black', inactivefg = 'black', **kw)
45
46 Valid resource names: background, bd, bg, borderwidth, class,
47 colormap, container, cursor, height, highlightbackground,
48 highlightcolor, highlightthickness, relief, takefocus, visual, width, activerelief,
49 inactiverelief, xpad, ypad.
50
51 xpad and ypad are values to be used as ipady and ipadx
52 with the Label widgets that make up the tabs. activefg and inactivefg define what
53 color the text on the tabs when they are selected, and when they are not
54
55 """
56 #Make various argument available to the rest of the class
57 self.activefg = activefg
58 self.inactivefg = inactivefg
59 self.deletedTabs = []
60 self.xpad = xpad
61 self.ypad = ypad
62 self.activerelief = activerelief
63 self.inactiverelief = inactiverelief
64 self.kwargs = kw
65 self.tabVars = {} #This dictionary holds the label and frame instances of each tab
66 self.tabs = 0 #Keep track of the number of tabs
67 self.noteBookFrame = Frame(parent) #Create a frame to hold everything together
68 self.BFrame = Frame(self.noteBookFrame) #Create a frame to put the "tabs" in
69 self.noteBook = Frame(self.noteBookFrame, relief = RAISED, bd = 2, **kw) #Create the frame that will parent the frames for each tab
70 self.noteBook.grid_propagate(0) #self.noteBook has a bad habit of resizing itself, this line prevents that
71 Frame.__init__(self)
72 self.noteBookFrame.grid()
73 self.BFrame.grid(row =0, sticky = W)
74 self.noteBook.grid(row = 1, column = 0, columnspan = 27)
75
76 def change_tab(self, IDNum):
77 """Internal Function"""
78
79 for i in (a for a in range(0, len(self.tabVars.keys()))):
80 if not i in self.deletedTabs: #Make sure tab hasen't been deleted
81 if i <> IDNum: #Check to see if the tab is the one that is currently selected
82 self.tabVars[i][1].grid_remove() #Remove the Frame corresponding to each tab that is not selected
83 self.tabVars[i][0]['relief'] = self.inactiverelief #Change the relief of all tabs that are not selected to "Groove"
84 self.tabVars[i][0]['fg'] = self.inactivefg #Set the fg of the tab, showing it is selected, default is black
85 else: #When on the tab that is currently selected...
86 self.tabVars[i][1].grid() #Re-grid the frame that corresponds to the tab
87 self.tabVars[IDNum][0]['relief'] = self.activerelief #Change the relief to "Raised" to show the tab is selected
88 self.tabVars[i][0]['fg'] = self.activefg #Set the fg of the tab, showing it is not selected, default is black
89
90 def add_tab(self, width = 2, **kw):
91 """Creates a new tab, and returns it&#x27;s corresponding frame
92
93 """
94
95 temp = self.tabs #Temp is used so that the value of self.tabs will not throw off the argument sent by the label's event binding
96 self.tabVars[self.tabs] = [Label(self.BFrame, relief = RIDGE, **kw)] #Create the tab

Callers 1

demoFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected