-
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
[Bug] Arrow keys not recognized in Events #3907
Comments
The error popup tells you exactly the problem with your program, including the file, the line number, and the single line of code. "Space bar" is activating your button. You should see that it has focus and a space bar will activate the button. Take a look at the popup you posted and see if you understand the error it's pointing out and why you got it. |
Apologies, I guess I lumped the spacebar error erroneously in with the original issue. Thanks for pointing that out. The arrow key functionality is really what I'm looking to achieve, and it seems either PySimpleGUI or Tkinter don't know how to handle them on OSX. Additionally, I don't know how I'll be able to deal with mouse clicks or drag events if they are just showing up as generic '0' events. |
It's all good. OSX/Mac and tkinter are a mess. It's that simple, but it's complex in how, and it's far-reaching in impact. |
There was a change for mouse events and graphs that are only on GitHub at the moment. You'll benefit from upgrading to 3.34.0.22 or whatever is on GitHub at the moment. There's an issue opened about graph coordinates, etc, that was recently changed. Maybe this is what you're describing. Take a look at recent issues. |
gtop = sg.Graph(canvas_size=(1200, 600),
graph_bottom_left=(0, 0),
graph_top_right=(500, 500),
background_color="black",
enable_events=True,
drag_submits=True) Put keys oni EVERYTHING that you expect to interact with. Don't use defaults on anything except Buttons. gtop = sg.Graph(canvas_size=(1200, 600),
graph_bottom_left=(0, 0),
graph_top_right=(500, 500),
background_color="black",
enable_events=True,
drag_submits=True,
key='-GRAPH-') |
Oh, I should have mentioned that adding a key won't fix your problem. I'm not sure what's up with that unfortunately. With version 3.34.0 on windows, I'm able to get the coordinates in the values dictionary. The screen capture slows this way down, but does demonstrate that I'm getting the coordinates. Please open a new issue for this graph thing if you want support on it. import PySimpleGUI as sg
gtop = sg.Graph(canvas_size=(1200, 600),
graph_bottom_left=(0, 0),
graph_top_right=(500, 500),
background_color="black",
enable_events=True,
drag_submits=True,
key='-GRAPH-')
print(sg.version)
layout = [[gtop],
[sg.Output(size=(80,10))],
[sg.Button('Show'), sg.Button('Exit')]]
window = sg.Window('Window Title', layout, return_keyboard_events=True)
while True: # Event Loop
event, values = window.read()
print(event, values)
if event == sg.WIN_CLOSED or event == 'Exit':
break
window.close() |
I get coordinates no problem, just as you do. There's just no way to handle them because the event is not seen as unique. A mouse click is not seen differently than a mouse drag, so I can't look for one vs the other. Understand the tkinter issues, I'll probably switch to windows box for this project, thanks for the assistance! |
Keep track of the "State" of your application. Look at the previous event to see if there was a mouse up for example to signal the end of dragging. Have you looked at the graph demos to see how they're done there? |
I don't know how I overlooked it, but I just checked again and yes, you mention the unique behavior of dragging. Understand now, this gets me what I was looking to do. I'll close the issue, thank you! |
The new "Demo Browser" makes it easy to search inside all of the demo files, run them, edit them. https://github.com/PySimpleGUI/PySimpleGUI/blob/master/DemoPrograms/Demo_Demo_Programs_Browser.py You can search for things like which programs enable keyboard input. |
Type of Issues (Bug)
Operating System
OSX 11.2.1
Python version
3.7.4
PySimpleGUI Port and Version
Ports = tkinter
PySimpleGUI Version: 4.34.0
tkinter version: 8.6.8
Your Experience Levels In Months or Years
2 months Python programming experience
2 years Programming experience overall
No ____ Have used another Python GUI Framework (tkinter, Qt, etc) previously (yes/no is fine)?
You have completed these steps:
Description of Problem / Question / Details
While an event is triggered, it just responds with a generic "super mario" question box character when I press any of the directional arrows on my Macbook Pro. Event received is just a '0' for mouse clicks as well as mouse drags. Mouse up does respond with a '(0, '+up')' event. Seems the rest of the keys work as expected. Spacebar throws an error, attached.
Code To Duplicate
The text was updated successfully, but these errors were encountered: