Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Enhancement] Focus first button in popup() calls #6652

Open
8 tasks done
Xoriun opened this issue Jan 22, 2024 · 9 comments
Open
8 tasks done

[Enhancement] Focus first button in popup() calls #6652

Xoriun opened this issue Jan 22, 2024 · 9 comments
Labels
Port - TK PySimpleGUI

Comments

@Xoriun
Copy link

Xoriun commented Jan 22, 2024

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]

  • Searched main docs for your problem www.PySimpleGUI.org
  • Looked for Demo Programs that are similar to your goal. It is recommend you use the Demo Browser! Demos.PySimpleGUI.org
  • If not tkinter - looked for Demo Programs for specific port
  • For non tkinter - Looked at readme for your specific port if not PySimpleGUI (Qt, WX, Remi)
  • Run your program outside of your debugger (from a command line)
  • Searched through Issues (open and closed) to see if already reported Issues.PySimpleGUI.org
  • Upgraded to the latest official release of PySimpleGUI on PyPI
  • Tried using the PySimpleGUI.py file on GitHub. Your problem may have already been fixed but not released

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:

sg.popup_ok('text', title='title', focus_first_button=True)
@PySimpleGUI
Copy link
Owner

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....

image

@Xoriun
Copy link
Author

Xoriun commented Jan 23, 2024

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...

@PySimpleGUI
Copy link
Owner

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.

@PySimpleGUI
Copy link
Owner

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

image

@PySimpleGUI
Copy link
Owner

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.

image
image

@jason990420
Copy link
Collaborator

jason990420 commented Mar 4, 2024

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)

image
image
image
image
image

@PySimpleGUI
Copy link
Owner

The commands psgwatermarkon and psgwatermarkoff will add/remove the watermark that's in my images above like this one:

image

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.

@PySimpleGUI PySimpleGUI added the Port - TK PySimpleGUI label Mar 5, 2024
@PySimpleGUI
Copy link
Owner

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.

@PySimpleGUI
Copy link
Owner

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Port - TK PySimpleGUI
Projects
None yet
Development

No branches or pull requests

3 participants