اذهب إلى المحتوى
  • 0

تصحيح للكود في ربط الكلاس ببعض

Ahmed Ahmed64

السؤال

تصحيح للكود في ربط الكلاس ببعض

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()

 

تم التعديل في بواسطة Ahmed Ahmed64
رابط هذا التعليق
شارك على الشبكات الإجتماعية

Recommended Posts

  • 0

من ناحية الكلاس والتوريث لا توجد مشاكل بالكود، ولكن هناك بعض الملاحظات الطفيفة لمعالجة بعض المشاكل،

أولًا: في أزرار الأوامر يجب تغيير المعامل 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']

 

رابط هذا التعليق
شارك على الشبكات الإجتماعية

انضم إلى النقاش

يمكنك أن تنشر الآن وتسجل لاحقًا. إذا كان لديك حساب، فسجل الدخول الآن لتنشر باسم حسابك.

زائر
أجب على هذا السؤال...

×   لقد أضفت محتوى بخط أو تنسيق مختلف.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   جرى استعادة المحتوى السابق..   امسح المحرر

×   You cannot paste images directly. Upload or insert images from URL.

  • إعلانات

  • تابعنا على



×
×
  • أضف...