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

[Bug] Arrow keys not recognized in Events #3907

Closed
8 tasks done
Rider328 opened this issue Feb 14, 2021 · 11 comments
Closed
8 tasks done

[Bug] Arrow keys not recognized in Events #3907

Rider328 opened this issue Feb 14, 2021 · 11 comments

Comments

@Rider328
Copy link

Rider328 commented Feb 14, 2021

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:

  • Read instructions on how to file an Issue
  • Searched through main docs http://www.PySimpleGUI.org for your problem
  • Searched through the readme for your specific port if not PySimpleGUI (Qt, WX, Remi)
  • Looked for Demo Programs that are similar to your goal http://www.PySimpleGUI.com
  • Note that there are also Demo Programs under each port on GitHub
  • Run your program outside of your debugger (from a command line)
  • Searched through Issues (open and closed) to see if already reported
  • Try again by upgrading your PySimpleGUI.py file to use the current one on GitHub. Your problem may have already been fixed but is not yet on PyPI.

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.

error

Code To Duplicate

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)
layout = [[gtop],
          [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
    if event == 'Show':
        # change the "output" element to be the value of "input" element
        window['-OUTPUT-'].update(values['-IN-'])

window.close()
@PySimpleGUI
Copy link
Owner

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.

@Rider328
Copy link
Author

Rider328 commented Feb 15, 2021

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.

@PySimpleGUI
Copy link
Owner

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.

@PySimpleGUI
Copy link
Owner

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.

@PySimpleGUI
Copy link
Owner

PySimpleGUI commented Feb 15, 2021

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-')

@PySimpleGUI
Copy link
Owner

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()

8ajZQ4ib0q

@Rider328
Copy link
Author

Rider328 commented Feb 15, 2021

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!

@PySimpleGUI
Copy link
Owner

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?

@Rider328
Copy link
Author

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!

@PySimpleGUI
Copy link
Owner

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.

@PySimpleGUI
Copy link
Owner

And, the "Project Browser" demo is being expanded to show the matches, etc.

These changes will get rolled back into the demo programs browser.

image

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

No branches or pull requests

2 participants