ما مشكلة هذا الخطأ
_tkinter.TclError: window ".!menu" isn't a top-level window
الكود كامل هنا
import customtkinter
import tkinter as tk
from tkinter import filedialog, messagebox, ttk
import pandas as pd
from pathlib import Path
class App(customtkinter.CTk):
def __init__(self):
super().__init__()
self.title("App-v1")
self.grid_columnconfigure(0, weight = 1)
self.grid_rowconfigure(1, weight = 1)
Menu(self)
def File_dialog(self):
self.filename = filedialog.askopenfilename(initialdir="C:\\Users\\Cakow\\PycharmProjects\\Main", title="Open file okay?", filetypes=(("text files", "*.xlsx"),("all files", "*.*")))
self.label_file["text"] = self.filename
return None
def Load_excel_data(self):
file_path = self.label_file["text"]
try:
excel_filename = r"{}".format(file_path)
if excel_filename[-4:] == ".csv":
df = pd.read_csv(excel_filename)
else:
df = pd.ExcelFile(excel_filename)
self.optionmenu1.configure(values = df.sheet_names)
self.label2["text"] = df.sheet_names
except ValueError:
tk.messagebox.showerror("Information", "The file you have chosen is invalid")
return None
except FileNotFoundError:
tk.messagebox.showerror("Information", f"No such file as {file_path}")
return None
class Menu(customtkinter.CTkFrame,App):
def __init__(self, master):
super().__init__(master)
self.grid(row=0, column=0, padx=(10, 10), pady=(10, 10), sticky="e")
self.columnconfigure(0, weight = 1)
self.rowconfigure(1, weight = 1)
self.create_widgets()
def create_widgets(self):
self.button1 = customtkinter.CTkButton(self, text = 'Button 1',command=self.File_dialog)
self.button1.grid(row = 0, column = 0, sticky = 'e')
self.label_file = ttk.Label(self, text="")
self.label_file.grid(row = 1, column = 0, sticky = 'e')
self.button2 = customtkinter.CTkButton(self, text = 'Button 1',command=self.Load_excel_data)
self.button2.grid(row = 2, column = 0, sticky = 'e')
self.label2 = ttk.Label(self, text="")
self.label2.grid(row = 3, column = 0, sticky = 'e')
self.optionmenu1 = customtkinter.CTkOptionMenu(self,values=["إختر ورقة العمل"], font=customtkinter.CTkFont(family="Calibri", size=12, weight="bold"))
self.optionmenu1.grid(row=4, column=0, padx=(10, 10), pady=(10, 10), sticky="e")
app = App()
app.mainloop()