Skip to content

Tabview image, how do I add it #2718

Answered by dipeshSam
Sonic3Modder asked this question in Q&A
Discussion options

You must be logged in to vote

This is how you can add icons to the buttons of CTktabview. I inherited the class and overrode the method add(). An extra method update_icon() is also added to update icon of an existing tab.

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 …

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by Sonic3Modder
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants