Ahmed Ahmed64 نشر 30 ديسمبر 2023 أرسل تقرير مشاركة نشر 30 ديسمبر 2023 (معدل) تصحيح للكود في ربط الكلاس ببعض import customtkinter from tkinter import filedialog from pathlib import Path import pandas as pd class App(customtkinter.CTk): def __init__(self): super().__init__() self.FilePath = None self.sh = None self.title("App-v1") self.grid_columnconfigure(0, weight=1) self.grid_rowconfigure(1, weight=1) customtkinter.set_appearance_mode("dark") customtkinter.set_default_color_theme("green") Frame_A = Frame1(self) Frame_A.grid(row=0, column=0, padx=(10, 10), pady=(10, 10), sticky="ew",columnspan=2) Frame_A.grid_columnconfigure(0, weight=1) Frame_A.configure(border_width=1,border_color="#0087f2") Frame_B = Frame2(self) Frame_B.grid(row=1, column=0, padx=(10, 10), pady=(10, 10), sticky="news") Frame_B.grid_columnconfigure(0, weight=1) Frame_B.configure(border_width=1,border_color="#0087f2") def LoadFile(self): self.FilePath = filedialog.askopenfilename(initialdir="C:\\Users\\Cakow\\PycharmProjects\\Main", title="Open file okay?", filetypes=(("text files", "*.xlsx"), ("all files", "*.*"))) return(self.FilePath) def LoadFile1(self): df = pd.ExcelFile(self.FilePath) self.sh= df.sheet_names print(self.sh) class Frame1(customtkinter.CTkFrame): def __init__(self, master): super().__init__(master) self.label1 = customtkinter.CTkLabel(self, text="Welcome", fg_color="transparent", font=customtkinter.CTkFont(family="Calibri", size=18, weight="bold"),justify="center") self.label1.grid(row=0, column=0, padx=(10, 10), pady=(10, 10), sticky="n") class Frame2(customtkinter.CTkFrame): def __init__(self, master): super().__init__(master) self.button1 = customtkinter.CTkButton(self, text="Open File", font=customtkinter.CTkFont(family="Calibri", size=12, weight="bold"),command=App.LoadFile) self.button1.grid(row=0, column=0, padx=(10, 10), pady=(10, 10), sticky="e") self.button2 = customtkinter.CTkButton(self, text="Open File", font=customtkinter.CTkFont(family="Calibri", size=12, weight="bold"),command=App.LoadFile1) self.button2.grid(row=0, column=0, padx=(10, 10), pady=(10, 10), sticky="e") app = App() app.mainloop() تم التعديل في 30 ديسمبر 2023 بواسطة Ahmed Ahmed64 اقتباس رابط هذا التعليق شارك على الشبكات الإجتماعية More sharing options...
0 El Sayed El Tohamy نشر 17 يناير أرسل تقرير مشاركة نشر 17 يناير من ناحية الكلاس والتوريث لا توجد مشاكل بالكود، ولكن هناك بعض الملاحظات الطفيفة لمعالجة بعض المشاكل، أولًا: في أزرار الأوامر يجب تغيير المعامل command ليكون بالشكل التالي: #self.button1 = customtkinter.CTkButton(self, text="Open File", font=customtkinter.CTkFont(family="Calibri", size=12, weight="bold"),command=App.LoadFile) self.button1 = customtkinter.CTkButton(self, text="Open File", font=customtkinter.CTkFont(family="Calibri", size=12, weight="bold"),command=lambda: App.LoadFile(self)) #self.button2 = customtkinter.CTkButton(self, text="Open File", font=customtkinter.CTkFont(family="Calibri", size=12, weight="bold"),command=App.LoadFile1) self.button2 = customtkinter.CTkButton(self, text="Open File", font=customtkinter.CTkFont(family="Calibri", size=12, weight="bold"),command=lambda: App.LoadFile1(self)) #self.button2.grid(row=0, column=0, padx=(10, 10), pady=(10, 10), sticky="e") # كذلك تغيير قيمة المعامل # row # لإظهار الزر بالصف الثاني self.button2.grid(row=1, column=0, padx=(10, 10), pady=(10, 10), sticky="e") تم تجربة الكود بعد التعديلات، ويعمل بشكل صحيح، وتم إعطاؤه ملف إكسيل فعرض في المخرجات: ['Sheet1'] اقتباس رابط هذا التعليق شارك على الشبكات الإجتماعية More sharing options...
السؤال
Ahmed Ahmed64
تصحيح للكود في ربط الكلاس ببعض
رابط هذا التعليق
شارك على الشبكات الإجتماعية
1 جواب على هذا السؤال
Recommended Posts
انضم إلى النقاش
يمكنك أن تنشر الآن وتسجل لاحقًا. إذا كان لديك حساب، فسجل الدخول الآن لتنشر باسم حسابك.