From ae71a8d31b869b0fab0ff63e096d85c7f2e9952f Mon Sep 17 00:00:00 2001 From: Markus Koller Date: Fri, 24 Feb 2023 11:18:15 +0100 Subject: [PATCH] Tkinter plot_canvas.draw() Crash Tkinter might have issues with thread safety: https://github.com/matplotlib/matplotlib/issues/13293 --- src/csv_threading.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/csv_threading.py b/src/csv_threading.py index 3fa05e5..9e35c69 100644 --- a/src/csv_threading.py +++ b/src/csv_threading.py @@ -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