tkinter-pp icon indicating copy to clipboard operation
tkinter-pp copied to clipboard

Two ideas

Open Moosems opened this issue 2 years ago • 9 comments

First, can you make it possible to bind the notebook tab close to a function? Second, can you put this on PyPi?

Moosems avatar Jul 07 '22 22:07 Moosems

https://pypi.org/project/tkinterpp/

rdbende avatar Jul 07 '22 23:07 rdbende

Any way for the first?

Moosems avatar Jul 08 '22 03:07 Moosems

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.

rdbende avatar Jul 08 '22 08:07 rdbende

Hmm what data does the event send? Can I get the tab index from it?

Moosems avatar Jul 08 '22 15:07 Moosems

No. It doesn't send any data 😕 https://github.com/Dogeek/tkinter-pp/blob/a2a161c1993fc04c48840aca0b2886a50963f53f/tkinterpp/notebooks.py#L47

rdbende avatar Jul 08 '22 15:07 rdbende

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

Moosems avatar Jul 08 '22 15:07 Moosems

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}"))

rdbende avatar Jul 08 '22 17:07 rdbende

Us there a way to call directly to tcl/tk for that?

Moosems avatar Jul 08 '22 17:07 Moosems

I found this answer which could work

Moosems avatar Jul 08 '22 17:07 Moosems