Hacktoberfest 2026: los issues que los mantenedores marcaron para octubre, abiertos y aptos para principiantes. Explorar issues de Hacktoberfest

[Enhancement] Keyboard events with modifiers, and Tkinter Key events

Abierto
#6,591 2 comentarios 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
4/5
Tiempo estimado
3-5 días
Aptitud para principiantes
35/100
Tipo de issue
Nueva funcionalidad
Claridad
Bastante claro
Estado de actividad
Estancado
Stack tecnológico
python
Área
desktop

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

Abrir la guía de contribución

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de PySimpleGUI/PySimpleGUI

Todos los issues de PySimpleGUI/PySimpleGUI

Issues similares

Más issues de Python

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.