tkinter-pp
tkinter-pp copied to clipboard
Two ideas
First, can you make it possible to bind the notebook tab close to a function? Second, can you put this on PyPi?
https://pypi.org/project/tkinterpp/
Any way for the first?
Looking at the source code, there's an event for that. You can bind your function to the <<NotebookTabClosed>>
virtual event, that will be generated after the tab is closed.
Hmm what data does the event send? Can I get the tab index from it?
No. It doesn't send any data 😕 https://github.com/Dogeek/tkinter-pp/blob/a2a161c1993fc04c48840aca0b2886a50963f53f/tkinterpp/notebooks.py#L47
How could I send data in a virtual event? I think I might make a pull request with some changes so that with both notebooks it sends data like the index of the closed tab or the index of the tab moved and which spot it went to.
NOTE:
I just found something that could work. If we have an attribute that has the index of the closed tab that changes before the event is sent then we can ask for the attributes value to get certain data. I also found this
I also found this
Yes, there's a data
field in Tk, but for some reason Tkinter doesn't support it. You can send data with a virtual event
w.event_generate("<<Event>>", data=str(tab_index))
but the event object doesn't have that attribute
>>> hasattr(event, "data")
False
If you really want to, you can some other field, but that's a bit hacky imo
w.event_generate("<<Event>>", x=tab_index)
w.bind("<<Event>>", lambda event: print(f"Tab index: {event.x}"))
Us there a way to call directly to tcl/tk for that?
I found this answer which could work