Tkinter plot_canvas.draw() Crash

Tkinter might have issues with thread safety:
https://github.com/matplotlib/matplotlib/issues/13293
This commit is contained in:
2023-02-24 11:18:15 +01:00
parent c138facd59
commit ae71a8d31b
+5 -2
View File
@@ -99,7 +99,8 @@ class ExecCSVThread(Thread):
try:
for j in range(4):
avx_lines[j].set_data([t, t], [0, 1])
parent.plot_canvas.draw() # equivalent to matplotlib.show()
print("The next line might crash the programm, outcomment if necessary")
#parent.plot_canvas.draw() # equivalent to matplotlib.show()
except DeviceAccessError as e:
ui_print("Failed to update figure: ", e)
@@ -177,6 +178,7 @@ def display_plot(parent): # create plot of fixed size (pixels) from array
# Create plot
figure = plot_field_sequence(parent.sequence_array, width, height) # create figure to be displayed
# Clear previous plots first
try:
if parent.plot_canvas is not None:
parent.plot_canvas.get_tk_widget().destroy()
@@ -190,7 +192,8 @@ def display_plot(parent): # create plot of fixed size (pixels) from array
axes[2].axvline(x=0, color="r"), axes[3].axvline(x=0, color="r")]
# Show new plot
parent.plot_canvas = FigureCanvasTkAgg(figure, parent.plot_frame) # create canvas to draw figure on
parent.plot_canvas.draw() # equivalent to matplotlib.show()
print("The next line might crash the programm, outcomment if necessary")
#parent.plot_canvas.draw() # equivalent to matplotlib.show()
parent.plot_canvas.get_tk_widget().grid(row=0, column=0, sticky="nesw") # place canvas in the UI
return figure, avx_lines