Skip to content

[ Bug ] - Closing External Matplotlib window causes segfault within python #6006

@patrickjimenez

Description

@patrickjimenez

Error

Closing an external Matplotlib window causes segfault within python


Operating System

MacOs 13.0

PySimpleGUI Port (tkinter, Qt, Wx, Web)

tinter


Versions

*** Version information copied to your clipboard. Paste into your GitHub Issue. ***

Python version: 3.9.7 (default, Sep 16 2021, 08:50:36)
[Clang 10.0.0 ]
port: tkinter
tkinter version: 8.6.11
PySimpleGUI version: 4.60.4
PySimpleGUI filename: /Users/patrickjimenez/Documents/_Capstone/ui/env/lib/python3.9/site-packages/PySimpleGUI/PySimpleGUI.py


Your Experience In Months or Years (optional)

Years Python programming experience
5
Years Programming experience overall
5
Have used another Python GUI Framework? (tkinter, Qt, etc) (yes/no is fine)
no
Anything else you think would be helpful?

The segfault also occurs in the Demo_Matplotlib_Two_Windows.py demo file


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
  • 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 run the demo program. I click "Plot". Matplotlib shows a plot. I close the Matplotlib plot. Python crashes.

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:

from matplotlib import use
import PySimpleGUI as sg
# import PySimpleGUIQt as sg; use('qt5agg')
import matplotlib.pyplot as plt

"""
    Simultaneous PySimpleGUI Window AND a Matplotlib Interactive Window
    A number of people have requested the ability to run a normal PySimpleGUI window that
    launches a MatplotLib window that is interactive with the usual Matplotlib controls.
    It turns out to be a rather simple thing to do.  The secret is to add parameter block=False to plt.show()
"""

def draw_plot():
    plt.plot([0.1, 0.2, 0.5, 0.7])
    plt.show(block=False)

layout = [[sg.Button('Plot'), sg.Cancel(), sg.Button('Popup')]]

window = sg.Window('Have some Matplotlib....', layout)

while True:
    event, values = window.read()
    if event in (sg.WIN_CLOSED, 'Cancel'):
        break
    elif event == 'Plot':
        draw_plot()
    elif event == 'Popup':
        sg.popup('Yes, your application is still running')
window.close()

Screenshot, Sketch, or Drawing

Screenshot 2022-11-03 at 5 14 53 PM


Watcha Makin?

If you care to share something about your project, it would be awesome to hear what you're building.

Metadata

Metadata

Assignees

No one assigned

    Labels

    QuestionFurther information is requested

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions