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

Question - Select input on focus after enter #5407

Closed
5 tasks
gk1701 opened this issue Apr 26, 2022 · 6 comments
Closed
5 tasks

Question - Select input on focus after enter #5407

gk1701 opened this issue Apr 26, 2022 · 6 comments
Labels
Port - TK PySimpleGUI question Further information is requested

Comments

@gk1701
Copy link

gk1701 commented Apr 26, 2022

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.

@jason990420
Copy link
Collaborator

jason990420 commented Apr 26, 2022

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)

@jason990420 jason990420 added question Further information is requested Port - TK PySimpleGUI labels Apr 26, 2022
@gk1701
Copy link
Author

gk1701 commented Apr 26, 2022

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.

@PySimpleGUI
Copy link
Owner

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.

@gk1701
Copy link
Author

gk1701 commented May 3, 2022

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

@PySimpleGUI
Copy link
Owner

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

image

@PySimpleGUI
Copy link
Owner

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.

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

No branches or pull requests

3 participants