Hello,
I have created a GUI using Tkinter (on a Windows 11 PC) that includes a mataplotlib graph, and when I run it from Python Spyder it compiles and runs correctly. However, if I run this GUI by double clicking the py file (not running inside Spyder), the GUI will partly display the graph, and then the GUI will crash and close down.
When the GUI runs, the graph displays and is updated every 10 seconds when the function power_meter_graph function is called - I think Spyder must be masking a coding error or something. Below are the key snippets of my code:
Can you see any obvious code errors?
Many thanks in advance,
Tuurbo46
import matplotlib.pyplot as plt
from matplotlib.backends.backend_tkagg import(FigureCanvasTkAgg)
from matplotlib.figure import Figure
root = tk.Tk()
fig_2, ax = plt.subplots(1, 1, figsize=(4, 3))
#---- pwrmeter label ----
lbl_6 = ttk.LabelFrame(tab2, text = "POWER METER")
lbl_6.grid(column=1, row=1, padx=20, pady=20, sticky='n')
#---- draw graph ----
canvas_2 = FigureCanvasTkAgg(fig_2, lbl_6)
canvas_2.get_tk_widget().grid_forget()
canvas_2.get_tk_widget().grid(column=0, row=0, padx=20, pady=20, columnspan=1, rowspan=1)
def power_meter_graph():
ccdf_table = pwrmeter_n1912a.read_n1912a_channel_a_ccdf_table()
ccdf_table_2 = np.fromstring(ccdf_table, sep=',')
x_values = np.array([ccdf_table_2[8], ccdf_table_2[7], ccdf_table_2[6],
ccdf_table_2[5], ccdf_table_2[4], ccdf_table_2[3]])
y_values = np.array([0.0001, 0.001, 0.01, 0.1, 1, 10]) # %
plt.yscale('log')
plt.ylabel("%")
plt.xlabel("dB")
plt.plot(x_values, y_values)
plt.show()

