I've implemented a Tkinter Notebook with multiple tabs, each of which contains the context of some text file. If the user changes the text, I would like to change the appearance of the tab so the user can see which tabs contain unsaved changes. For instance, in Nodepad++, there is a diskette icon changing its color.
Is there a way of changing the appearance of the tabs in the Notebook? I know there is a possibility to define a style at the creation time of the tab. But the examples I found use styles depending on pre-defined states of the tabs like "disabled", "pressed", "active", etc. I tried user-defined state, e.g. "text_inside_tab_changed", but I get the error _tkinter.TclError: Invalid state name
.
Here is a minimal example:
# Import the required libraries
from tkinter import *
from tkinter import ttk
text = None
nb = None
def on_key(event):
# text["state"]="tab_content_changed" <-- does not work
# nb.tab(text, image=PhotoImage("floppy-disk.png")) <-- my png image does not appear
# how can I change the appearance of the tab here?
print(nb.tab(text))
pass
# Create an instance of tkinter frame
win = Tk()
# Set the size of the tkinter window
win.geometry("700x350")
# Create a Notebook widget
nb = ttk.Notebook(win)
# Add a text frame
text = Text(nb, width=400, height=180)
text.bind_all('<Key>', on_key)
nb.add(text, text='Text File', compound='left')
nb.pack(fill=BOTH, padx=5, pady=5)
win.mainloop()
Sorry, I have no idea how to add/change images in the tab.