Open Xoriun opened 10 months ago
It's really annoying
I totally understand that! I suggest writing your own small popup function to use instead of the PySimpleGUI one. They're very short functions normally and you can get them exactly the way you want them. Life's too short to wait around for an enhancement like this when you can write a solution yourself in the meantime..... give it a try and see if you can write one in a few minutes....
I know it's not that hard, I just need to set focus=True
on the button constructor I want to have initial focus.
But since I imagine that there are others who would welcome this change I opened this issue, so not everyone who wants this has to write their own spin-off version or edit their local copy of PySimpleGUI...
Until you see something official, I recommend not modifying the PySimpleGUI file and to make your own function. Otherwise you'll overwrite your changes, have to merge changes, and other headaches.
Finally had a moment to look at this. I thought this was already in the code, and indeed the focus is set on the left-most button by default. It's not working on newer versions of tkinter however, so some tkinter release broke this particular feature. The same for the input popups like popup_get_text
.
The popup code already sets focus=True
so not sure where you added it to your code.
PopupButton('OK', size=(6, 1), button_color=button_color, focus=True, bind_return_key=True)
Here's a popup that has the focus on the OK button... running on tkinter 8.6.6 on Windows
It looks like tkinter 8.6.10, 8.6.11, or 8.6.12 broke this feature. Not sure which at this point as I don't have 10 or 11 on this machine.
import sys
import PySimpleGUI as sg
layout = [
[sg.Button("OK", focus=True)],
[sg.Text(f"Python:{sys.version.split()[0]}"),
sg.Text(f"PySimpleGUI:{sg.ver}"),
sg.Text(f"tkinter:{sg.tclversion_detailed}")],
]
sg.Window("Title", layout).read(close=True)
The commands psgwatermarkon
and psgwatermarkoff
will add/remove the watermark that's in my images above like this one:
The badge, showing "verified" in this example, refers to the security check that's run when PySimpleGUI is imported.
It's was helpful when developing PSG5 to be able to see the Python version, tkinter version and PySimpleGUI version running so I left the feature in and enabled control over it in the settings window and from the command line.
I see you've got the same results Jason... 8.6.12 and 8.6.13 don't show focus on the button and 8.6.9 does.
We started seeing some problems in 8.6.12 so if I had to guess, it would be that version where the trouble began.
I've not yet tested this on Linux nor Mac, so not sure if tkinter broke it there as well. Before I make any fixes I want to make sure I have all the data and don't end up going backwards overall.
I am seeing a similar problem on Linux when using tkinter 8.6.12 on Python 3.10. So it appears to be a tkinter introduced problem. I'll get the Mac checked too.
Type of Issue (Enhancement, Error, Bug, Question)
Enhancement
Environment
Operating System
Windows version ('10', '10.0.19045', 'SP0', 'Multiprocessor Free')
PySimpleGUI Port (tkinter, Qt, Wx, Web)
tkinter
Versions
Python version (
sg.sys.version
)3.11.6 (tags/v3.11.6:8b6ee5b, Oct 2 2023, 14:57:12) [MSC v.1935 64 bit (AMD64)]
PySimpleGUI Version (
sg.__version__
)4.61.0.198
GUI Version (tkinter (
sg.tclversion_detailed
), PySide2, WxPython, Remi)8.6.12
Your Experience In Months or Years (optional)
2 Years Python programming experience 10 Years Programming experience overall Yes Have used another Python GUI Framework? (tkinter, Qt, etc) (yes/no is fine)
Troubleshooting
These items may solve your problem. Please check those you've done by changing - [ ] to - [X]
Detailed Description
When using the popup() calls, it would be really nice if there was a way to focus the first button by default. I encountered this when checking for some input and creating popups if they were malformed. It's really annoying always having to touch the moouse or try tabbing through the popup if it only contains text and one button.
Something like the following would be enough: