[issue44592] tkinter focus_get() with non-tkinter Tk widget

2021-07-17 Thread Akuli
Akuli added the comment: Typo in previous message: I meant `widget.focus_get() is None`. It currently means "this application doesn't have focus", while `is not None` currently means "this application has focus". -- ___ Python tracker

[issue44592] tkinter focus_get() with non-tkinter Tk widget

2021-07-17 Thread Akuli
Akuli added the comment: Here are the options: - Do nothing. My program will error in some corner cases. - Change it to return `None`, so `widget.focus_get() is not None` no longer means "this application doesn't have focus", but rather "this application doesn't have focus or the focused wi

[issue44592] tkinter focus_get() with non-tkinter Tk widget

2021-07-16 Thread Terry J. Reedy
Terry J. Reedy added the comment: Traceback (most recent call last): File "C:\Programs\Python310\lib\tkinter\__init__.py", line 1921, in __call__ return self.func(*args) File "C:\Programs\Python310\lib\tkinter\__init__.py", line 839, in callit func(*args) File "C:\Programs\Python3

[issue44592] tkinter focus_get() with non-tkinter Tk widget

2021-07-09 Thread Akuli
Akuli added the comment: Unfortunately I don't know any real-world examples of this on Windows. The open file dialog works very differently on Windows: it uses the native Windows dialog, whereas on Linux, it's implemented in Tcl. Meanwhile, here's a platform-independent toy example: imp

[issue44592] tkinter focus_get() with non-tkinter Tk widget

2021-07-09 Thread Terry J. Reedy
Terry J. Reedy added the comment: I am not quite convinced that this is a duplicate of #734176. The latter is about tearoff clones and nothing is cloned here. But I do notice that number 'names were also prefixed with '#'. What happens if 'tearoff=0' is added to the cascade so that it is no

[issue44592] tkinter focus_get() with non-tkinter Tk widget

2021-07-09 Thread Terry J. Reedy
Terry J. Reedy added the comment: Akuli, what tk widgets do you think are not known to tkinter? In any case, tk menu is known to tkinter. I cannot reproduce when running on Windows with 3.10.0b3: Add "print(root.children)" (after add_cascade) results in {'!menu': , '!menu2': }. The names

[issue44592] tkinter focus_get() with non-tkinter Tk widget

2021-07-09 Thread Akuli
Akuli added the comment: I found issue734176 before I created this. It is NOT a duplicate. While issue734176 is about menus, this one is about focus_get(), and not necessarily related to menus. In fact, I initially noticed this with an "open file" dialog, not with a menu. I'm not putting my

[issue44592] tkinter focus_get() with non-tkinter Tk widget

2021-07-09 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: It is a duplicate of issue734176. -- resolution: -> duplicate stage: -> resolved status: open -> closed superseder: -> Make Tkinter.py's nametowidget work with cloned menu widgets ___ Python tracker

[issue44592] tkinter focus_get() with non-tkinter Tk widget

2021-07-09 Thread E. Paine
E. Paine added the comment: Sorry, I should specify that we would use `winfo class` in order to then return a new tkinter object for the existing Tk widget (which currently cannot be done) -- ___ Python tracker

[issue44592] tkinter focus_get() with non-tkinter Tk widget

2021-07-09 Thread E. Paine
E. Paine added the comment: I agree with Akuli that raising a KeyError is not expected behaviour (combined with the fact this is caught elsewhere), and therefore is probably a regression. While we could use `winfo class` to determine the type of Tk widget, this would probably require a reaso

[issue44592] tkinter focus_get() with non-tkinter Tk widget

2021-07-09 Thread Akuli
Akuli added the comment: Forgot to mention: The correct fix IMO would be to return None when a KeyError occurs. This way code like `focus_get() == some_tkinter_widget` would always do the right thing, for example. -- ___ Python tracker

[issue44592] tkinter focus_get() with non-tkinter Tk widget

2021-07-09 Thread Akuli
New submission from Akuli : The purpose of focus_get() is to return the widget that currently has the focus. It tries to convert its result to a tkinter widget, which can fail, because not all Tk widgets are known to tkinter. Consider this, for example: import tkinter def print_focus