mirror of
https://github.com/TomSchimansky/CustomTkinter.git
synced 2023-08-10 21:13:13 +03:00
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:
@@ -365,6 +365,22 @@ class CTkTabview(CTkBaseClass):
|
|||||||
else:
|
else:
|
||||||
raise ValueError(f"CTkTabview has no tab named '{name}'")
|
raise ValueError(f"CTkTabview has no tab named '{name}'")
|
||||||
|
|
||||||
def get(self) -> str:
|
def get(self, index: int = None) -> str:
|
||||||
""" returns name of selected tab, returns empty string if no tab selected """
|
""" returns name of selected tab, returns empty string if no tab selected\n
|
||||||
return self._current_name
|
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)
|
||||||
Reference in New Issue
Block a user