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

[ Bug] sg.WIN_CLOSED event is not generated, after catching mouse down events in same window for read_all_windows calls

Abierto
#6,691 4 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
28/100
Tipo de issue
Error
Claridad
Bastante claro
Estado de actividad
Estancado
Stack tecnológico
python
Área
desktop

Línea de trabajo

Reproduce el problema con el ejemplo proporcionado usando sg.read_all_windows, un Graph con change_submits y drag_submits, y el port de tkinter en macOS. Comienza con la implementación de read_all_windows en PySimpleGUI.py y el manejo de eventos de Graph. Se considera terminado cuando hacer clic en Graph y después en el icono de cierre de la ventana produce sg.WIN_CLOSED y sale del bucle de eventos como se espera.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

Type of Issue (Enhancement, Error, Bug, Question)

Bug


Operating System

MacOs 10.14.6

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: 3.12.2 | packaged by conda-forge | (main, Feb 16 2024, 21:00:12) [Clang 16.0.6 ]
port: tkinter
tkinter version: 8.6.13
PySimpleGUI version: 4.60.5
PySimpleGUI filename: /Users/cm/anaconda3/envs/sg/lib/python3.12/site-packages/PySimpleGUI/PySimpleGUI.py

Python version (sg.sys.version)

3.12.2 | packaged by conda-forge | (main, Feb 16 2024, 21:00:12) [Clang 16.0.6 ]

PySimpleGUI Version (sg.__version__)

4.60.5

GUI Version (tkinter (sg.tclversion_detailed), PySide2, WxPython, Remi)

8.6.13


Your Experience In Months or Years (optional)

Years Python programming experience
4 years

Years Programming experience overall
30 years

Have used another Python GUI Framework? (tkinter, Qt, etc) (yes/no is fine)
no

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 running the Development Build. Your problem may have already been fixed but not released
Detailed Description

The sg.WIN_CLOSED event is not generated, after catching mouse down events in same window.
If I open a window and if I hit the "window close" icon in the left upper corner (MacOsX), the close event is generated and the window closes and in the event loop is exited.

If I click inside of the window before clicking the close window icon, it will not accept the close window icon any more. If I click on the close icon I get the window, event, value as follows:
<PySimpleGUI.PySimpleGUI.Window object at 0x10a700a10> -GRAPH2-+UP {'-GRAPH2-': (3, 293)}

The coordinate is a coordinate inside of the close window icon.
This only happens after generating a mouse down event in the window.

Code To Duplicate

This pre-formatted code block is all set for you to paste in your bit of code:


import PySimpleGUI as sg
from PIL import Image, ImageDraw, ImageTk
import io

## Indeed, it should be possible to combine the following two create window functions to one general function:
def make_overview_window(h, w):
    layout_overview_window = [[sg.Graph(
        canvas_size=(h, w),
        graph_bottom_left=(0, 0),
        graph_top_right=(h, w),
        key="-GRAPH1-",
        change_submits=True,  # mouse click events
        background_color='white',
        drag_submits=True), ],
        [sg.Text(key='info1', size=(60, 1))]]

    return sg.Window("Main zoom selection window", layout_overview_window, finalize=True)

if __name__ == '__main__':
    # Load JPG images using Pillow
    image1 = Image.open('image1.jpg')
    h0, w0 = image1.size

    print("Size: ", h0, " ", w0)

    # Convert images to bytes
    img_bytes1 = io.BytesIO()
    image1.save(img_bytes1, format='PNG')
    window_overview = make_overview_window(h0, w0)

    # get the graph element for ease of use later
    graph_overview_window = window_overview["-GRAPH1-"]
    graph_overview_window.draw_image(data=img_bytes1.getvalue(), location=(0, h0))

    while True:
        window, event, values = sg.read_all_windows() # timeout=10)

        print(window, event, values)
        if window == window_overview:
            if event == sg.WIN_CLOSED:
                break  # exit

            if event == "-GRAPH1-":  # if there's a "Graph" event, then it's a mouse
                x, y = values["-GRAPH1-"]
                print(event, " ", x, " ", y)

    # Close the window
    window_overview.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.