[Enhancement] Keyboard events with modifiers, and Tkinter Key events
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Aptitud para principiantes
- 35/100
Línea de trabajo
Comienza con la reproducción proporcionada, especialmente con la configuración de la ventana, las llamadas a Graph bind y el bucle window.read(). Investiga cómo PySimpleGUI reenvía los eventos de teclado de Tkinter y la información de los modificadores; después, verifica el comportamiento de Ctrl, Alt, Shift, Key, KeyPress y KeyUp. Se considera terminado cuando los eventos de los modificadores son coherentes y las vinculaciones de teclado demostradas producen eventos utilizables.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
Type of Issue (Enhancement, Error, Bug, Question)
Enhancement
Operating System
Windows 11 pro
PySimpleGUI Port (tkinter, Qt, Wx, Web)
tkinter
Versions
Version information can be obtained by calling sg.main_get_debug_data()
Or you can print each version shown in ()
Python version (sg.sys.version)
3.10.8 (tags/v3.10.8:aaaf517, Oct 11 2022, 16:50:30) [MSC v.1933 64 bit (AMD64)]
PySimpleGUI Version (sg.__version__)
4.60.5
GUI Version (tkinter (sg.tclversion_detailed), PySide2, WxPython, Remi)
8.6.12
Your Experience In Months or Years (optional)
Years Python programming experience
10+
Years Programming experience overall
40+
Have used another Python GUI Framework? (tkinter, Qt, etc) (yes/no is fine)
wxPython
Anything else you think would be helpful?
Troubleshooting
These items may solve your problem. Please check those you've done by changing - [ ] to - [X]
- Searched main docs for your problem www.PySimpleGUI.org
- Looked for Demo Programs that are similar to your goal. It is recommend you use the Demo Browser! Demos.PySimpleGUI.org
- None of your GUI code was generated by an AI algorithm like GPT
- 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
- Have upgraded to the latest release of PySimpleGUI on PyPI (lastest official version)
- Tried using the PySimpleGUI.py file on GitHub. Your problem may have already been fixed but not released
Detailed Description
I need to handle quite a few keyboard events for a project; let's say I need to recognize any letter [a-z] with any combination of <Ctrl> and <Alt>.
The behaviour of return_keyboard_events=True is a bit of a surprise to me; I expected a "Ctrl-a" event, not two subsequent events, one for the "a" and then one for Ctrl. But this is something that can be partly managed, since the event for "a" is different in the two cases: just "a" when the key is pressed alone, and "a:65" when it is pressed with Ctrl. So when we get "a:65" we know we need to wait for the next event, although if the user typed something like "Ctrl-a-b", without releasing Ctrl, the probem would arise again (they would not see the effect of their first command until they input the second one).
But for "Alt" the behaviour is different: in that case the event for the normal key is "a" again.
So this brings to the enhancement proposal: it would be very nice if we had a single event, showing the key AND the modifier(s); but at least Ctrl and Alt (and Shift) should behave in the same way.
At this point I turned to binding the Tkinter event, and found the error: it didn't work for any of <Key>, <KeyPress>, <KeyUp>. Just to check I tried <Enter> and <Button-3> and they worked like a charm.
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:
import PySimpleGUI as sg
grid = [[sg.Graph(canvas_size=(450,450), graph_bottom_left=(0.0,9.0), graph_top_right=(9.0,0.0),
background_color="light grey", key="the_grid", float_values=True,
enable_events=True)],
[sg.Ok(key="OK")]
]
text_elem = sg.Text(size=(30, 1))
grid[-1].append(text_elem)
##window = sg.Window('The Grid', grid, return_keyboard_events=True, use_default_focus=False, finalize=True)
window = sg.Window('The Grid', grid, finalize=True)
window["the_grid"].bind("<KeyUp>", "+keypress") #if we replace the event with <Enter> it works
window["the_grid"].bind("<Button-3>", "+rightclick")
for r in range(9):
for c in range(9):
window["the_grid"].draw_rectangle(top_left=(r+0.05,c+0.05), bottom_right=(r+0.95,c+0.95), fill_color="white")
window.refresh()
cnt = 0
while True:
event, values = window.read() #a right click is intercepted, a keypress is not
cnt += 1
if event in [sg.WIN_CLOSED, "OK"]:
break
text_elem.update(f'{event} {values}')
print(cnt, event)
if '+' in event:
print('got!', window["the_grid"].user_bind_event)
window.close()
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.
- Lenguaje dominante
- Python
- Estrellas
- 13.8k
- Forks
- 1.8k
- Métricas de merge de PR
- Sin PR fusionados en 30 d
Guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de PySimpleGUI/PySimpleGUI
-
Bug Done - Install Dev Build (see docs for how) Platform Specific Issue - Linux Port - TK
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
PySimpleGUI/PySimpleGUI#6904 · 15 comentarios ·
-
Bug Demo Programs Done - Install Dev Build (see docs for how) Interoperability Port - TK workaround available
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
PySimpleGUI/PySimpleGUI#6900 · 1 comentario ·
-
Done - Install Dev Build (see docs for how) enhancement
Dificultad 2/5 1-3 horas Aptitud para principiantes 62/100
PySimpleGUI/PySimpleGUI#3251 · 12 comentarios ·
-
Dificultad 3/5 1-2 días Aptitud para principiantes 74/100
PySimpleGUI/PySimpleGUI#6906 · 1 comentario · 1 reacción ·
-
Bug Done - Install Dev Build (see docs for how) Port - TK
Dificultad 3/5 1-2 días Aptitud para principiantes 45/100
PySimpleGUI/PySimpleGUI#6902 · 1 comentario ·
Todos los issues de PySimpleGUI/PySimpleGUI
Issues similares
-
essnmx good first issue
Dificultad 1/5 Menos de una hora Aptitud para principiantes 95/100
-
[Feature] 奇物选择添加优先级 Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 65/100
syfoud/Simulated_Scepter#174 ·
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 75/100
Giskard-AI/giskard-oss#2840 · 1 comentario ·
-
A claim comment carrying the issue number is silently declined while the workflow reports success Abiertoarea: repo bug perceived difficulty: 2
Dificultad 2/5 1-3 horas Aptitud para principiantes 70/100
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 75/100
yeti-platform/yeti#1380 ·