Update ctk_tabview.py

Adding two methods to the class CTkTabview":
"index" to return the index (position) of the current tab or the tab entered as an attribute.
"len" method to return the number of defined tabs

Modifying the "get" method: it now returns the name of the selected tab, or an empty string if no tab is selected. If an index is defined, it returns the name associated with that index.
This commit is contained in:
fgosdrauka 2023-04-05 12:49:59 +02:00
parent 09e584634c
commit af054f502c

View File

@ -365,6 +365,22 @@ class CTkTabview(CTkBaseClass):
else:
raise ValueError(f"CTkTabview has no tab named '{name}'")
def get(self) -> str:
""" returns name of selected tab, returns empty string if no tab selected """
return self._current_name
def get(self, index: int = None) -> str:
""" returns name of selected tab, returns empty string if no tab selected\n
if an index is defined, return the associated name """
if index == None:
return self._current_name
else:
return self._name_list[index]
def index(self, name=""):
""" returns index of selected tab, returns empty int if no tab selected\n
if a name is defined, return the associated index """
if name == "":
return self._name_list.index(self._current_name)
else:
return self._name_list.index(name)
def len(self):
""" return the number of defined tabs """
return len(self._name_list)