Tabview image, how do I add it #2718
Answered
by
dipeshSam
Sonic3Modder
asked this question in
Q&A
-
So, Im downloading bootstrap icons in my program, but I would like to add images to a tabview, like how you can add images to a CTkButton. Im hoping someone can help |
Beta Was this translation helpful? Give feedback.
Answered by
dipeshSam
Apr 29, 2025
Replies: 1 comment
-
This is how you can add icons to the buttons of Here is the code: from customtkinter import CTk, CTkTabview, CTkImage
from PIL.Image import open as img_open
class Tabview(CTkTabview):
def __init__(self, master, *args, **kwargs):
super().__init__(master, *args, **kwargs)
def add(self, name: str, icon: CTkImage = None):
"Updated method to accept icon."
ref = super().add(name)
if icon:
button = self._segmented_button._buttons_dict[name]
button.configure(image = icon, fg_color=button.cget("fg_color")) # Force the fg_color after image updation
return ref
def update_icon(self, name: str, icon: CTkImage):
"New method to update/add icon to existing tab."
button = self._segmented_button._buttons_dict[name]
button.configure(image = icon, fg_color=button.cget("fg_color"))
if __name__ == "__main__":
app = CTk()
tabview = Tabview(app, fg_color="lightblue")
tabview.pack(padx=20, pady=20)
icon1 = CTkImage(img_open("icon1.png"), size=(16, 16))
icon2= CTkImage(img_open("icon2.png"), size=(16, 16))
icon3 = CTkImage(img_open("icon3.png"), size=(16, 16))
tab1 = tabview.add("Tab 1", icon1)
tab2 = tabview.add("Tab 2", icon2)
tab3 = tabview.add("Tab 3", icon3)
tab4 = tabview.add("Tab 4", icon3)
app.mainloop() |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
Sonic3Modder
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is how you can add icons to the buttons of
CTktabview
. I inherited the class and overrode the methodadd()
. An extra methodupdate_icon()
is also added to update icon of an existing tab.Here is the code: