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

Method add_tab

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

Creates a new tab, and returns it's corresponding frame

(self, width = 2, **kw)

Source from the content-addressed store, hash-verified

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'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
97 self.tabVars[self.tabs][0].bind("<Button-1>", lambda Event:self.change_tab(temp)) #Makes the tab "clickable"
98 self.tabVars[self.tabs][0].pack(side = LEFT, ipady = self.ypad, ipadx = self.xpad) #Packs the tab as far to the left as possible
99 self.tabVars[self.tabs].append(Frame(self.noteBook, **self.kwargs)) #Create Frame, and append it to the dictionary of tabs
100 self.tabVars[self.tabs][1].grid(row = 0, column = 0) #Grid the frame ontop of any other already existing frames
101 self.change_tab(0) #Set focus to the first tab
102 self.tabs += 1 #Update the tab count
103 return self.tabVars[temp][1] #Return a frame to be used as a parent to other widgets
104
105 def destroy_tab(self, tab):
106 """Delete a tab from the notebook, as well as it&#x27;s corresponding frame

Callers 1

demoFunction · 0.95

Calls 7

change_tabMethod · 0.95
LabelClass · 0.85
FrameClass · 0.50
bindMethod · 0.45
packMethod · 0.45
appendMethod · 0.45
gridMethod · 0.45

Tested by

no test coverage detected