MCPcopy
hub / github.com/PySimpleGUI/PySimpleGUI / add_tab

Method add_tab

PySimpleGUI/PySimpleGUI.py:7741–7809  ·  view source on GitHub ↗

Add a new tab to an existing TabGroup This call was written so that tabs can be added at runtime as your user performs operations. Your Window should already be created and finalized. :param tab_element: A Tab Element that has a layout in it :type tab_elemen

(self, tab_element)

Source from the content-addressed store, hash-verified

7739 return key
7740
7741 def add_tab(self, tab_element):
7742 """
7743 Add a new tab to an existing TabGroup
7744 This call was written so that tabs can be added at runtime as your user performs operations.
7745 Your Window should already be created and finalized.
7746
7747 :param tab_element: A Tab Element that has a layout in it
7748 :type tab_element: Tab
7749 """
7750
7751 self.add_row(tab_element)
7752 tab_element.TKFrame = tab_element.Widget = tk.Frame(self.TKNotebook)
7753 form = self.ParentForm
7754 form._BuildKeyDictForWindow(form, tab_element, form.AllKeysDict)
7755 form.AllKeysDict[tab_element.Key] = tab_element
7756 # Pack the tab's layout into the tab. NOTE - This does NOT pack the Tab itself... for that see below...
7757 PackFormIntoFrame(tab_element, tab_element.TKFrame, self.ParentForm)
7758
7759 # - This is below - Perform the same operation that is performed when a Tab is packed into the window.
7760 # If there's an image in the tab, then do the imagey-stuff
7761 # ------------------- start of imagey-stuff -------------------
7762 try:
7763 if tab_element.Filename is not None:
7764 photo = tk.PhotoImage(file=tab_element.Filename)
7765 elif tab_element.Data is not None:
7766 photo = tk.PhotoImage(data=tab_element.Data)
7767 else:
7768 photo = None
7769
7770 if tab_element.ImageSubsample and photo is not None:
7771 photo = photo.subsample(tab_element.ImageSubsample)
7772 # print('*ERROR laying out form.... Image Element has no image specified*')
7773 except Exception as e:
7774 photo = None
7775 _error_popup_with_traceback('Your Window has an Tab Element with an IMAGE problem',
7776 'The traceback will show you the Window with the problem layout',
7777 'Look in this Window\'s layout for an Image tab_element that has a key of {}'.format(tab_element.Key),
7778 'The error occuring is:', e)
7779
7780 tab_element.photo = photo
7781 # add the label
7782 if photo is not None:
7783 width, height = photo.width(), photo.height()
7784 tab_element.tktext_label = tk.Label(tab_element.ParentRowFrame, image=photo, width=width, height=height, bd=0)
7785 else:
7786 tab_element.tktext_label = tk.Label(tab_element.ParentRowFrame, bd=0)
7787 # ------------------- end of imagey-stuff -------------------
7788
7789 state = 'normal'
7790 if tab_element.Disabled:
7791 state = 'disabled'
7792 if tab_element.visible is False:
7793 state = 'hidden'
7794 if photo is not None:
7795 self.TKNotebook.add(tab_element.TKFrame, text=tab_element.Title, compound=tk.LEFT, state=state, image=photo)
7796 else:
7797 self.TKNotebook.add(tab_element.TKFrame, text=tab_element.Title, state=state)
7798 tab_element.ParentNotebook = self.TKNotebook

Callers

nothing calls this directly

Calls 7

add_rowMethod · 0.95
PackFormIntoFrameFunction · 0.85
ToolTipClass · 0.85
_add_right_click_menuFunction · 0.85
addMethod · 0.45

Tested by

no test coverage detected