From af054f502cec61d41b594f5ba9a5711af7fdede5 Mon Sep 17 00:00:00 2001 From: fgosdrauka Date: Wed, 5 Apr 2023 12:49:59 +0200 Subject: [PATCH] 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. --- customtkinter/windows/widgets/ctk_tabview.py | 22 +++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/customtkinter/windows/widgets/ctk_tabview.py b/customtkinter/windows/widgets/ctk_tabview.py index 75bde4b..40321b4 100644 --- a/customtkinter/windows/widgets/ctk_tabview.py +++ b/customtkinter/windows/widgets/ctk_tabview.py @@ -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) \ No newline at end of file