-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
sg.In() , sg.FilesBrowse() reads Browse button as input value #1527
Comments
Everything is working fine. Just don't write Now.
Here is your code in normal form: import PySimpleGUI as sg
layout = [
[sg.Text('Filename')],
[sg.Input(), sg.FileBrowse()],
[sg.OK(), sg.Cancel()]
]
window = sg.Window('Simple App, Really simple.', layout)
while True:
event, values = window.Read()
if event is None or event == 'Exit': break
print(event, values)
if event == 'Button1':
pass
if event == 'Button2':
pass
if event == 'Button3':
pass
window.Close() |
The old version returns value as a list. The new version returns value as a dictionary. This is what I tried.
A. psg v3.28
B. psg v3.37
The following would cause a ValueError in the new version as indicated by @DKatarakis |
The problem is that Buttons started to return values too. This created an extra entry and because it's a button it switched the return values over to a dictionary. If you reference v[0] it will give you your value (same as a list), but it's held in a dictionary. I'm puzzled why the button is returning a value now. Lemme read the release notes and see if I can determine what the purpose was. I have a feeling it's due to something with the calendar widget or other specialty button. |
Yes indeed. I apologize for not specifying properly. Thanks for your input. |
Upon further examination, there was a change a while back to Button return values across all 4 ports. This was a fundamental change to buttons. They now have return values. This poses a real problem for applications that attempt to "unpack" the results as it's not a list. I'll discourage direct unpacking in the Documentation. You can access the return values as if the values were a list using [], you just can't unpack them directly. Sorry about this! Breaking existing code upon upgrading is a cardinal sin to me so I'm really very sorry. You'll need to modify your code access the returned values in 2 steps instead of 1. |
Your 1-line program became 2 I'm afraid event, values = sg.Window('Get filename example'). Layout([[sg.Text('Filename')], [sg.Input(), sg.FileBrowse()], [sg.OK(), sg.Cancel()] ]).Read()
filename = values[0] |
After updating to latest version seems the code for taking file inputs doesn't work anymore
event, (filename,) = sg.Window('Get filename example'). Layout([[sg.Text('Filename')], [sg.Input(), sg.FileBrowse()], [sg.OK(), sg.Cancel()] ]).Read()
It produces ValueError: too many values to unpack (expected 1).
Upon investigating a bit it seems that in 3.39.0 the Browse button originating from FileBrowse() is read as an input. Downgrading to 3.29.0 fixed the issue. Tested with FileInput() as well.
The text was updated successfully, but these errors were encountered: