Replies: 1 comment
-
I've created a function from customtkinter import CTk, CTkTabview, CTkLabel
def sort_tabs(tabs: CTkTabview):
"""Sorts all the tabs of `CTkTabView` in lexicographical order."""
for i, sorted_name in enumerate(sorted(tabs._name_list)):
tabs._segmented_button.move(i, sorted_name)
tabs.update()
if __name__ == "__main__":
app = CTk()
tabs = CTkTabview(app, width=400)
tabs.pack(padx=20, pady=20)
mango = tabs.add("Mango")
apple = tabs.add("Apple")
orange = tabs.add("Orange")
banana = tabs.add("Banana")
grape = tabs.add("Grape")
label_font = ("Arial", 30)
CTkLabel(mango, text="This is Mango tab.", font = label_font).place(relx=0.5, anchor="center", rely=0.5)
CTkLabel(apple, text="This is Apple tab.", font = label_font).place(relx=0.5, anchor="center", rely=0.5)
CTkLabel(orange, text="This is Orange tab.", font = label_font).place(relx=0.5, anchor="center", rely=0.5)
CTkLabel(banana, text="This is Banana tab.", font = label_font).place(relx=0.5, anchor="center", rely=0.5)
CTkLabel(grape, text="This is Grape tab.", font = label_font).place(relx=0.5, anchor="center", rely=0.5)
# Calling sorting method
sort_tabs(tabs)
app.mainloop() Hope this would be helpful for you. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Is there a way to sort tabs in a tabview once they have been added?
In detail with context:
I am adding tabs to a tabview at runtime based upon incoming data.
tabview.add()
works fine, however I would like to re-order these tabs in lexographical order. From what I can see in the docs, this cannot be done?My workaround is to store the data to make each tab externally, append to that when new data comes in, sort it, then
delete()
andadd()
in the new sorted order. This is obviously cumbersome and an interesting side effect is that the in focus tab is becomes blank until it is manually clicked on again.I can make a minimum working example if required, but in non optimal, psuedo-code to show the general workflow in case I'm missing an obvious:
Beta Was this translation helpful? Give feedback.
All reactions