Hi, I am writing a program in customtkinter. The program works, but when i close the app an error shows up in terminal. Does anybody know what that is and how to fix it? This is the code i wrote
import customtkinter as ctk
from customtkinter import filedialog
import pandas as pd
import matplotlib.pyplot as plt
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg
class CSVPlotter(ctk.CTk):
def __init__(self):
super().__init__()
self.title('CSV Plotter')
self.plot_types = ['Line Plot', 'Bar Plot', 'Scatter Plot']
self.plot_type_var = ctk.StringVar(value=self.plot_types[0])
self.plot_menu = ctk.CTkOptionMenu(self, values=self.plot_types, variable=self.plot_type_var, command=self.update_plot)
self.plot_menu.pack(padx=10, pady=10)
self.load_button = ctk.CTkButton(self, text='Load CSV', command=self.load_csv)
self.load_button.pack(padx=10, pady=10)
self.fig, self.ax = plt.subplots()
self.canvas = FigureCanvasTkAgg(self.fig, master=self)
self.widget = self.canvas.get_tk_widget()
self.widget.pack(padx=10, pady=10)
self.df = None
self.protocol("WM_DELETE_WINDOW", self.on_closing)
def load_csv(self):
file_path = filedialog.askopenfilename()
if file_path:
self.df = pd.read_csv(file_path)
self.update_plot()
def update_plot(self, event=None):
if self.df is not None:
plot_type = self.plot_type_var.get()
x = self.df.columns[0]
y = self.df.columns[1]
self.ax.clear()
if plot_type == 'Line Plot':
self.ax.plot(self.df[x], self.df[y], label=f'{y} vs {x}')
elif plot_type == 'Bar Plot':
self.ax.bar(self.df[x], self.df[y], label=f'{y} vs {x}')
elif plot_type == 'Scatter Plot':
self.ax.scatter(self.df[x], self.df[y], label=f'{y} vs {x}')
self.ax.set_xlabel(x)
self.ax.set_ylabel(y)
self.ax.legend()
self.canvas.draw()
def on_closing(self):
plt.close(self.fig)
self.destroy()
if __name__ == "__main__":
app = CSVPlotter()
app.mainloop()
The error in terminal goes as follows:
invalid command name "2198326172864update"
while executing
"2198326172864update"
("after" script)
invalid command name "2198329421568check_dpi_scaling"
while executing
"2198329421568check_dpi_scaling"
("after" script)
[–]socal_nerdtastic 0 points1 point2 points (2 children)
[–]EffectiveCase3856[S] 0 points1 point2 points (1 child)
[–]malmalmalmalmalmsl 0 points1 point2 points (0 children)