Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[Bug]: blitting after closing second tkinter embed causes silent crash #23809

Copy link
Copy link
Closed
@Alex-x90

Description

@Alex-x90
Issue body actions

Bug summary

After opening a tkinter popup and embedding a figure a second time and closing it, blitting the figure again causes a silent complete program crash.

Code for reproduction

from tkinter import *
import numpy as np
import matplotlib
matplotlib.use("Agg")
import matplotlib.pyplot as plt
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg

mainWindow = Tk()

fig = plt.figure()
ax = fig.add_subplot(1,1,1)
img = ax.imshow(np.random.rand(28,28), cmap="gray", interpolation="None")
fig.canvas.draw()

canvas = FigureCanvasTkAgg(fig, master=mainWindow)
canvas.draw()
canvas.get_tk_widget().grid(row=1, column=1)

def openPopup():
    popup = Tk()

    popupCanvas = FigureCanvasTkAgg(fig, master=popup)
    popupCanvas.draw()
    popupCanvas.get_tk_widget().grid(row=1, column=1)

    popup.protocol("WM_DELETE_WINDOW", popup.destroy)
    popup.mainloop()

def doBlit():
    img.set_data(np.random.rand(28,28))
    ax.draw_artist(img)
    
    fig.canvas.blit(ax.bbox) # this blit line is the cause of the crash

    fig.canvas.flush_events()

button_1 = Button(mainWindow,command=(openPopup),text="open popup")
button_1.grid(row=1,column=2)
button_2 = Button(mainWindow,command=(doBlit),text="do blitting")
button_2.grid(row=1,column=3)

mainWindow.mainloop()

Actual outcome

Program crashes with no error message.

Expected outcome

Either the program should crash with an error message, or the blit should succeed and the new image should be rendered.

Additional information

I think this is probably related to #16580, but the lack of any error message is definitely different. In the larger program where I'm trying this blitting doesn't actively crash in this way with a separate figure that has 2 scatterplots and a title which are being blitted and embedded in the same manner, but the other figure which is just an image is causing the program to crash. If anyone knows a way to fix this in the meantime I would be very grateful.

Operating system

Windows

Matplotlib Version

3.4.3

Matplotlib Backend

Agg

Python version

3.8.1

Jupyter version

6.4.6

Installation

pip

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.