PySimpleGUI / PySimpleGUI

Python GUIs for Humans! PySimpleGUI is the top-rated Python application development environment. Launched in 2018 and actively developed, maintained, and supported in 2024. Transforms tkinter, Qt, WxPython, and Remi into a simple, intuitive, and fun experience for both hobbyists and expert users.

Home Page:https://www.PySimpleGUI.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Question - Select input on focus after enter

gk1701 opened this issue · comments

Question - Select input on focus after enter


Operating System

WIN10 64

PySimpleGUI Port (tkinter, Qt, Wx, Web)


Versions

Python version: 3.10.2 (tags/v3.10.2:a58ebcc, Jan 17 2022, 14:12:15) [MSC v.1929 64 bit (AMD64)]
port: tkinter
tkinter version: 8.6.12
PySimpleGUI version: 4.57.0
PySimpleGUI filename: C:\Users\LDS\AppData\Local\Programs\Python\Python310\lib\site-packages\PySimpleGUI\PySimpleGUI.py

Python version (sg.sys.version)

PySimpleGUI Version (sg.__version__)

GUI Version (tkinter (sg.tclversion_detailed), PySide2, WxPython, Remi)


Your Experience In Months or Years (optional)

Years Python programming experience

Years Programming experience overall

Have used another Python GUI Framework? (tkinter, Qt, etc) (yes/no is fine)

Anything else you think would be helpful?


Troubleshooting

These items may solve your problem. Please check those you've done by changing - [ ] to - [X]

  • [x ] Searched main docs for your problem www.PySimpleGUI.org
  • [x ] Looked for Demo Programs that are similar to your goal 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
  • Tried using the PySimpleGUI.py file on GitHub. Your problem may have already been fixed but not released

Detailed Description

@jason,

Hi Jason,

still struggling with selection on enter. In your comment in issues/5301 the following part of the code does not seem to work on my windows pc.

if event == 'Return':
user_event = window.user_bind_event
user_event.widget.tk_focusNext().focus()
user_event.widget.tk_focusNext().select=True
select=True

I thought the second select=true may be the culprit, then I moved the if block to a different position, but to no avail.

Would your time permit to have another look at this, thank you.

Code To Duplicate

A short program that isolates and demonstrates the problem (Do not paste your massive program, but instead 10-20 lines that clearly show the problem)

This pre-formatted code block is all set for you to paste in your bit of code:

# Paste your code here

Screenshot, Sketch, or Drawing


Watcha Makin?

If you care to share something about your project, it would be awesome to hear what you're building.

It's about one month passed and almost all forgot.

It looks like following code paste from your demo code, and the statement select=True is useless.

if event == 'Return':
    user_event = window.user_bind_event
    user_event.widget.tk_focusNext().focus()
    user_event.widget.tk_focusNext().select=True
    select=True

Upgrade your PySimpleGUI from Github, then refer following link for new code
#5131 (comment)

Thank you Jason,

I have the latest version PySimpleGUI 4.59.0
#5131 (comment) relates to a topic tab on multiline. But no problem, I just remove the default and add

if event == 'Obj-Length' and values['Obj-Length'] and values['Obj-Length'][-1] not in ('0123456789.-'):
window['Obj-Length'].update(values['Obj-Length'][:-1])

and problem solved another way.

Did I mess something up with this? 4.58.0 was when the new propagate parm was added to the bind methods as well as the addition of a bunch of new focus capabilities.

Not sure what happened, however this piece below never worked

if event == 'Return':
user_event = window.user_bind_event
user_event.widget.tk_focusNext().focus()
user_event.widget.tk_focusNext().select=True
select=True

so a clumsy workaround was to use

if event == 'Return':
user_event = window.user_bind_event
user_event.widget.tk_focusNext().focus()

    if values['Obj-Length'] == '0.00':
         key = 'Obj-Length'        
         window[key].update(select=True)
    elif values['Obj-Length'] == '':
         window['Obj-Length'].update('0.00')

rinse and repeat for every element

obviously adding an awful extra lines

now the selection on enter works and because if user somehow deletes the default, calcs dont work, so as part of the event we restore the 0.00
Only problem remaining is if the user somehow blanks out the default and then uses tab instead of enter.
Jason had a nice piece of code on issue #5291 but have not been able to implement here

elif event.endswith('FocusOut'):
key = event.split('_')[0]
if values[key] == '':
window[key].update(default)
values[key] = default

The point was to remove all of the use of .widget for focus.

image

Then the other piece was the addition of propagate on the bind calls so that the return key is never added to the values dictionary. That's what the last example posted in #5131 was all about.... no use of widget and no having to remove the return key or tab key.