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

Ahmed Ahmed64

الأعضاء
  • المساهمات

    222
  • تاريخ الانضمام

  • تاريخ آخر زيارة

أجوبة بواسطة Ahmed Ahmed64

  1. بتاريخ 41 دقائق مضت قال Chihab Hedidi:

    هذه الميثود غير موجودة في مكتبة Pandas يمكن استعمال الميثود loc بحيث تقوم بالتأشير على السطر الأخير بعدها تضيف المعلومات فيه، و هذا كود لتفهم أكثر:

    df = pd.read_excel("example.xlsx")
    df.loc[len(df)] = row_information
    df.to_excel("example.xlsx", index=False)

     نستخدم loc لتحديد سطر في DataFrame باستخدام الفهرس (index). في هذا السياق، استخدمت len(df) للإشارة إلى السطر الأخير في DataFrame ومن ثم إضافة معلومات الصف الجديدة row_information إلى هذا السطر.

     

    هل يمكن توضيح أكثر

    row_information

    • أعجبني 1
  2. السلام عليكم

    مامفهوم هذا الخطأ

    AttributeError: 'DataFrame' object has no attribute 'append_df_to_excel'

    حيث أن لدي def  وظيفته أنه يقرأ أعمدة من اكسل وأجري عليها بعض العمليات ومن ثم تحويلها إلى DataFrame وتخزينها في ملف جديد

    الفكرة التي أحاول الوصول إليها 

    عند تنفيذ الكود مجدداً أريده أن يخزن البيانات الجديدة بحث يستكمل على أخر سطر في نفس الملف

    التخزين في نفس

    • أعجبني 1
  3. ما مشكلة هذا الخطأ

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

     

    • أعجبني 1
  4. أخي ماهي مشكلة هذا الخطأ

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

     

  5. السلام عليكم

    import tkinter as tk
    from tkinter import filedialog, messagebox, ttk
    import pandas as pd
    
    class App(tk.Tk):
        def __init__(self):
            super().__init__()
            self.title("App-v1")
            self.columnconfigure(0, weight = 1)
            self.rowconfigure(1, weight = 1)
            Menu(self)
            Load_excel_data()
        
        def File_dialog(self):
            """This Function will open the file explorer and assign the chosen file path to label_file"""
            filename = filedialog.askopenfilename(initialdir="/",
                                                  title="Select A File",
                                                  filetype=(("xlsx files", "*.xlsx"),("All Files", "*.*")))
            label_file["text"] = filename
            return None
    
    
        def Load_excel_data():
            """If the file selected is valid this will load the file into the Treeview"""
            file_path = label_file["text"]
            try:
                excel_filename = r"{}".format(file_path)
                if excel_filename[-4:] == ".csv":
                    df = pd.read_csv(excel_filename)
                else:
                    df = pd.read_excel(excel_filename)
    
            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(ttk.Frame):
        def __init__(self, parent):
            super().__init__(parent)
            
            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.menu_button1 = ttk.Button(self, text = 'Button 1',command=File_dialog)
            self.menu_button1.grid(row = 0, column = 0, sticky = 'e')
    
    app = App()
    app.mainloop()

     

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

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

     

  7. السلام عليكم

    أود أن أفهم بعض المصطلخات التي تستخدم ولماذا توضع 

    في الكود الثالي على سبيل المثال 

    class Frame_A(customtkinter.CTkFrame):
        def __init__(self, master):
            super().__init__(master)

    ما هي الفائدة من كلمة master

    كذلك كلمة super

    في حالة أردت ربط كلاس أخر مع هذا الكلاس أين يوضع اسم الكلاس المراد الربط به

  8. السلام عليكم ورحمة الله وبركاته

    لدي سؤال أود طرحة عليكم

    عند وجود أكثر  مع أكثر من class كيف يتم الوصول للمتغيرات

    فمثلا لدينا  class A  وهذا الكلاس به دالة تقوم بعملية وترجع الناتج داخل متغير

    واحتاج أن أتعامل مع هذا المتغير داخل class B مثلا

    سؤالي أحتاج شرح مبسط كيف أقوم بذلك 

     

    • أعجبني 1
  9. السلام عليكم

    أود مراجعة كتابة الكود والتصحيح عليه 

    class Frame2(customtkinter.CTkFrame):
        def __init__(self, master):
            super().__init__(master)
            
            def LoadFile():
                
                filepath = filedialog.askopenfilename(initialdir="C:\\Users\\Cakow\\PycharmProjects\\Main", title="Open file okay?", filetypes=(("text files", "*.xlsx"), ("all files", "*.*")))
                filepathA = Path(filepath)
                df = pd.ExcelFile(filepathA)
                return df
                
                self.optionmenu1.configure(values = sht())
            
            def sht():
                A1=self.Frame2.LoadFile
                B1 =A1.sheet_names
                return B1
                    
              
            self.button1 = customtkinter.CTkButton(self, text="إختيار ملف", font=customtkinter.CTkFont(family="Calibri", size=12, weight="bold"), command=LoadFile)
            self.button1.grid(row=0, column=1, padx=(10, 10), pady=(10, 10), sticky="e")
            
            self.optionmenu1 = customtkinter.CTkOptionMenu(self,values=["إختر ورقة العمل"], font=customtkinter.CTkFont(family="Calibri", size=12, weight="bold"))
            self.optionmenu1.grid(row=0, column=0, padx=(10, 10), pady=(10, 10), sticky="e")

     

  10. بتاريخ 28 دقائق مضت قال محمد سعد شحرور:

    بشكل عام، يمكنك الوصول الى خاصة ضمن class1 في class2 عن طريق انشاء مرجع في class2 تدل الى class1.

    أي أنه عليك انشاء مرجع لل frame2 لل frame4 للوصول الى خاصة ال df:

    class Frame4(customtkinter.CTkFrame):
      # عرف مرجع للكلاس الأول هنا
        def __init__(self, master, border_color, border_width, frame2_instance):
            super().__init__(master)
            self.configure(border_width=border_width, border_color=border_color)
    
            # قم بتخزين قيمة هذا المرجع
            self.frame2_instance = frame2_instance
    
           # باقي الكود الخاص بك

    بعد ذلك تعطي المرجع قيمة، وهي نسخة من ال frame2 لتستطيع الوصول الى كافة خواص ال frame2 ضمن ال frame4:

    frame2_instance = Frame2(master, border_color, border_width)
    frame4_instance = Frame4(master, border_color, border_width, frame2_instance)

    هل من توضيح أكثر أخي 

    • أعجبني 1
  11. السلام عليكم

    إخوتي لدي هذا الكلاس

    class Frame2(customtkinter.CTkFrame):
        def __init__(self, master, border_color, border_width):
            super().__init__(master)
            self.configure(border_width=border_width,border_color=border_color)
    
            self.df = None
    
            def LoadFile():
    
                filepath = filedialog.askopenfilename(initialdir="C:\\Users\\Cakow\\PycharmProjects\\Main", title="Open file okay?", filetypes=(("text files", "*.xlsx"), ("all files", "*.*")))
                filepathA = Path(filepath)
                self.df = pd.ExcelFile(filepathA)
                def optionmenu_callback(choice):
                    #print("optionmenu dropdown clicked:", choice)
                    self.label2.configure(text=choice)
                self.optionmenu1.configure(values = self.sht(),command=optionmenu_callback)
    
              
    		            
            self.button1 = customtkinter.CTkButton(self, text="إختيار ملف", font=customtkinter.CTkFont(family="Calibri", size=12, weight="bold"), command=LoadFile)
            self.button1.grid(row=0, column=1, padx=(10, 10), pady=(10, 10), sticky="nw")
            
            self.optionmenu1 = customtkinter.CTkOptionMenu(self,values=["إختر ورقة العمل"], font=customtkinter.CTkFont(family="Calibri", size=12, weight="bold"))
            self.optionmenu1.grid(row=0, column=0, padx=(10, 10), pady=(10, 10), sticky="nw")
            
            self.label2 = customtkinter.CTkLabel(self, text="", text_color="#0087f2", font=customtkinter.CTkFont(family="Calibri", size=14, weight="bold"))
            self.label2.grid(row=1, column=0, padx=(10, 10), pady=(10, 10), sticky="nw")
            
            self.label3 = customtkinter.CTkLabel(self, text="إسم ورقة العمل المختارة :", fg_color="transparent", font=customtkinter.CTkFont(family="Calibri", size=14, weight="bold"))
            self.label3.grid(row=1, column=1, padx=(10, 10), pady=(10, 10), sticky="nw")
            
        def sht(self):
                AD = self.df.sheet_names
                return AD

     

    ولدي هذا الكلاس

    class Frame4(customtkinter.CTkFrame):
        def __init__(self, master, border_color, border_width):
            super().__init__(master)
            self.configure(border_width=border_width,border_color=border_color)
            
            def cooll():
    
                
                selected_column_1 = self.df.iloc[8::2, [0,1,2,3,4,5,6]]
                selected_column_1.reset_index(drop=True, inplace=True)
                A = pd.DataFrame(selected_column_1)
                print(A) 
    
            self.checkbox_1 = customtkinter.CTkCheckBox(self, text="checkbox 1")
            self.checkbox_1.grid(row=0, column=0, padx=(10, 10), pady=(10, 10), sticky="news")
            
            self.button3 = customtkinter.CTkButton(self, text="طباعة العمود", font=customtkinter.CTkFont(family="Calibri", size=12, weight="bold"),command=cooll)
            self.button3.grid(row=1, column=0, padx=(10, 10), pady=(10, 10), sticky="nw")

    السؤال كيف أصل إلى الكلاس الأول من داخل الكلاس الثاني

    مثلا أريد أن أصل إلى self.df الموجودة في الكلاس الأول داخل الكلاس الثاني

    • أعجبني 1
  12. بتاريخ 37 دقائق مضت قال Ahmed Elmrsawy:

    السلام عليكم ,
    يمكنك محاولة ضبطها باستخدام رمز e الذي يرمز الى الشرق و هو ما يعادل اليمين , كما في المثال التالي 
     

    import CTkFrame
    
    app = CTkFrame.CTk()
    
    label = CTkFrame.Label(app, text="نص التسمية")
    label.grid(row=0, column=0, sticky="e")  # تعيين sticky="e" لتحديد اليمين
    
    app.run()

     

    السلام عليكم أخي

    قمت بتجربة ذلك ولاكن يبقى الزر في يسار الشاشة وأنا أريده في يمين الشاشة

    كما تعلم أخي أن شبكة الشاشة مقسمة إلى أعمدة وصفوف 

    فا العمود 0 والصف 0 مكانهم في الجانب العلوي الأيسر من الشاشة 

    كيف أقلبهم ناحية اليمين

    • أعجبني 1
  13. السلام عليكم

    أداة CTkFrame أخذت الصف 0 والعمود 0 بداخلها أداة label أخذت الصف 0 والعمود 0

    طبعا استخدمت grid في ترتيب الأدوات 

    سؤالي الأن كيف أجعل أداة label في محاذات الشاشة من اليمين ولا تظهر على اليسار

    وهل من طريقة لقلب النافذة الرئيسة

     

  14. بتاريخ 9 دقائق مضت قال Chihab Hedidi:

    نعم يمكنك ذلك بحدث الكود من داخل Fram1 و تكتبه داخل App بهذه الطريقة:
     

    import customtkinter
    
    
    class Frame1(customtkinter.CTkFrame):
        def __init__(self, master):
            super().__init__(master)
    
            self.button1 = customtkinter.CTkButton(self, text="إختيار ملف",
                                                   font=customtkinter.CTkFont(family="Calibri", size=12, weight="bold"))
            self.button1.grid(row=0, column=1, padx=3, pady=(3, 0), sticky="w")
    
    
    class Frame2(customtkinter.CTkFrame):
        def __init__(self, master):
            super().__init__(master)
            self.checkbox_1 = customtkinter.CTkCheckBox(self, text="checkbox 1")
            self.checkbox_1.grid(row=0, column=0, padx=3, pady=(3, 0), sticky="w")
    
    
    class Frame3(customtkinter.CTkFrame):
        def __init__(self, master):
            super().__init__(master)
            self.button2 = customtkinter.CTkButton(self, text="خروج", state="disabled",
                                                   font=customtkinter.CTkFont(family="Calibri", size=12, weight="bold"))
            self.button2.grid(row=0, column=0, padx=3, pady=(3, 0), sticky="w")
    
    
    class App(customtkinter.CTk):
        def __init__(self):
            super().__init__()
    
            self.title("my app")
            self.geometry("400x180")
            self.grid_columnconfigure(0, weight=1)
            self.grid_rowconfigure(0, weight=1)
    
            self.Frame_A = Frame1(self)
            self.Frame_A.configure(border_color="red", border_width=3 ,fg_color="blue")
            self.Frame_A.grid(row=0, column=0, padx=1, pady=(1, 0), sticky="nswe")
            self.Frame_B = Frame2(self)
            self.Frame_B.grid(row=0, column=1, padx=1, pady=(1, 0), sticky="nswe")
            self.Frame_C = Frame3(self)
            self.Frame_C.grid(row=1, column=0, padx=1, pady=(1, 10), sticky="nswe")
    
    
    app = App()
    app.mainloop()

     اما بخصوص التعريب يمكنك استخدام الميثود pack كهذا المثال:
     

    self.button1.pack(side="right")

     

    لدي هذا الخطأ 

    tkinter.TclError: cannot use geometry manager grid inside .!frame1 which already has slaves managed by pack

  15. بتاريخ 10 دقائق مضت قال Chihab Hedidi:

    في المثال الذي ارسلته قمت بالتمرير من داخل class App مثل الكود الذي كان موجود:

    self.Frame_A = Frame1(self, "red", 3, "blue")

    و هذا الكود كامل اذا اردت تجربه:

    import customtkinter
    
    
    class Frame1(customtkinter.CTkFrame):
        def __init__(self, master, border_color, border_width, fg_color):
            super().__init__(master)
            self.configure(border_width=border_width,border_color=border_color,fg_color=fg_color)
            self.button1 = customtkinter.CTkButton(self, text="إختيار ملف",
                                                   font=customtkinter.CTkFont(family="Calibri", size=12, weight="bold"))
            self.button1.grid(row=0, column=1, padx=3, pady=(3, 0), sticky="w")
    
    
    class Frame2(customtkinter.CTkFrame):
        def __init__(self, master):
            super().__init__(master)
            self.checkbox_1 = customtkinter.CTkCheckBox(self, text="checkbox 1")
            self.checkbox_1.grid(row=0, column=0, padx=3, pady=(3, 0), sticky="w")
    
    
    class Frame3(customtkinter.CTkFrame):
        def __init__(self, master):
            super().__init__(master)
            self.button2 = customtkinter.CTkButton(self, text="خروج", state="disabled",
                                                   font=customtkinter.CTkFont(family="Calibri", size=12, weight="bold"))
            self.button2.grid(row=0, column=0, padx=3, pady=(3, 0), sticky="w")
    
    
    class App(customtkinter.CTk):
        def __init__(self):
            super().__init__()
    
            self.title("my app")
            self.geometry("400x180")
            self.grid_columnconfigure(0, weight=1)
            self.grid_rowconfigure(0, weight=1)
    
            self.Frame_A = Frame1(self, "red", 3, "blue")
            self.Frame_A.grid(row=0, column=0, padx=1, pady=(1, 0), sticky="nswe")
            self.Frame_B = Frame2(self)
            self.Frame_B.grid(row=0, column=1, padx=1, pady=(1, 0), sticky="nswe")
            self.Frame_C = Frame3(self)
            self.Frame_C.grid(row=1, column=0, padx=1, pady=(1, 10), sticky="nswe")
    
    
    app = App()
    app.mainloop()


     

    أخي من الممكن أن سؤالي كان غير مفهوم لديك

    أقصد لماذا لم أمرر من خلال class App

    بحيث كتب مثلا  border_color = " red 

    لدي سؤال أخر 

    كيف أستطيع أن أجعل واجهة التطبيق تقرأ العمود 0 من ناحية اليمين وليس الشمال

    المقصود أخي تعريب الواجهة 

  16. بتاريخ 6 دقائق مضت قال Chihab Hedidi:

    يمكنك ذلك باستخدام الميثود configure و ذلك بإستخادم المدخلات الخاصة بك و هذا كود ال Frame1 معدل و يمكنك تعديل باقي الكود بنفس الطريقة:

    class Frame1(customtkinter.CTkFrame):
        def __init__(self, master, border_color, border_width, fg_color):
            super().__init__(master)
            self.configure(border_width=border_width,border_color=border_color,fg_color=fg_color)
            self.button1 = customtkinter.CTkButton(self, text="إختيار ملف",
                                                   font=customtkinter.CTkFont(family="Calibri", size=12, weight="bold"))
            self.button1.grid(row=0, column=1, padx=3, pady=(3, 0), sticky="w")

    و هذه صورة للنتيجة:

    Screenshot2023-12-27193843.png.5fc5346fe880f72277ed61cd57d9e46a.png

    أحسنت أخي بارك الله فيك

    إذا يجب إستخدام configure لذلك

    سؤال لماذا لايتم التمرير مباشرة داخل كلاس class App وهل يمكن ذلك

    self.Frame_A = Frame1(self)
            self.Frame_A.grid(row=0, column=0, padx=1, pady=(1, 0), sticky="nswe")

     

  17. السلام عليكم

    كيفه نطبق خصائص CTkFrame  مثل border_width أو border_color  على كود مكتوب بهذه الكيفية 

    حاولت ولاكن لم تنجح

    الرجاء التوضيح لو سمحتم

    import customtkinter
    
    class Frame1(customtkinter.CTkFrame):
        def __init__(self, master,border_color,border_width,fg_color):
            super().__init__(master)
            self.button1 = customtkinter.CTkButton(self, text="إختيار ملف", font=customtkinter.CTkFont(family="Calibri", size=12, weight="bold"))
            self.button1.grid(row=0, column=1, padx=3, pady=(3, 0), sticky="w")
    
    class Frame2(customtkinter.CTkFrame):
        def __init__(self, master):
            super().__init__(master)
            self.checkbox_1 = customtkinter.CTkCheckBox(self, text="checkbox 1")
            self.checkbox_1.grid(row=0, column=0, padx=3, pady=(3, 0), sticky="w")
    
    class Frame3(customtkinter.CTkFrame):
        def __init__(self, master):
            super().__init__(master)
            self.button2 = customtkinter.CTkButton(self, text="خروج", state="disabled", font=customtkinter.CTkFont(family="Calibri", size=12, weight="bold"))
            self.button2.grid(row=0, column=0, padx=3, pady=(3, 0), sticky="w")
    
    class App(customtkinter.CTk):
        def __init__(self):
            super().__init__()
    
            self.title("my app")
            self.geometry("400x180")
            self.grid_columnconfigure(0, weight=1)
            self.grid_rowconfigure(0, weight=1)
     
            self.Frame_A = Frame1(self,"red",10,"red")
            self.Frame_A.grid(row=0, column=0, padx=1, pady=(1, 0), sticky="nswe")
            self.Frame_B = Frame2(self)
            self.Frame_B.grid(row=0, column=1, padx=1, pady=(1, 0), sticky="nswe")
            self.Frame_C = Frame3(self)
            self.Frame_C.grid(row=1, column=0, padx=1, pady=(1, 10), sticky="nswe")
    
    app = App()
    app.mainloop()

     

    • أعجبني 1
  18. السلام عليكم

    معذرة أحتاج تصحيح في هذا الكود حيث أنه لدي أداة القائمة من المفترض عند اختيار الملف تمتلئ هذه القائمة

    الرجاء الاطلاع وتشغيل الكود وتصحيح الخطأ الذي به

    import customtkinter
    from tkinter import filedialog
    from pathlib import Path
    import pandas as pd
    
    class Frame1(customtkinter.CTkFrame):
        def __init__(self, master):
            super().__init__(master)
            self.AS = None
    
            def LoadFile():
                filepath = filedialog.askopenfilename(initialdir="C:\\Users\\Cakow\\PycharmProjects\\Main", title="Open file okay?", filetypes=(("text files", "*.xlsx"), ("all files", "*.*")))
                filepathA = Path(filepath)
                self.AS = pd.ExcelFile(filepathA)
                
                AD = self.sht()
    		
                self.optionmenu1.values = AD
    
            self.button1 = customtkinter.CTkButton(self, text="إختيار ملف", font=customtkinter.CTkFont(family="Calibri", size=12, weight="bold"), command=LoadFile)
            self.button1.grid(row=0, column=1, padx=3, pady=(3, 0), sticky="we")
    
            self.optionmenu1 = customtkinter.CTkOptionMenu(self)
            self.optionmenu1.grid(row=0, column=0, padx=3, pady=(3, 0), sticky="we")
    
        def sht(self):
            if self.AS:
                AD = self.AS.sheet_names
                return AD
            else:
                return []
    
    class Frame2(customtkinter.CTkFrame):
        def __init__(self, master):
            super().__init__(master)
            self.checkbox_1 = customtkinter.CTkCheckBox(self, text="checkbox 1")
            self.checkbox_1.grid(row=0, column=0, padx=3, pady=(3, 0), sticky="w")
    
    class Frame3(customtkinter.CTkFrame):
        def __init__(self, master):
            super().__init__(master)
    
            def button_event():
                print("خروج")
    
            self.button2 = customtkinter.CTkButton(self, text="خروج", state="disabled", font=customtkinter.CTkFont(family="Calibri", size=12, weight="bold"), command=button_event)
            self.button2.grid(row=0, column=0, padx=3, pady=(3, 0), sticky="w")
    
    class App(customtkinter.CTk):
        def __init__(self):
            super().__init__()
    
            self.title("my app")
            self.geometry("400x180")
            self.grid_columnconfigure(0, weight=1)
            self.grid_rowconfigure(0, weight=1)
            customtkinter.set_appearance_mode("dark")
            customtkinter.set_default_color_theme("dark-blue")
    
            self.Frame_A = Frame1(self)
            self.Frame_A.grid(row=0, column=0, padx=1, pady=(1, 0), sticky="nswe")
            self.Frame_B = Frame2(self)
            self.Frame_B.grid(row=0, column=1, padx=1, pady=(1, 0), sticky="nswe")
            self.Frame_C = Frame3(self)
            self.Frame_C.grid(row=1, column=0, padx=1, pady=(1, 10), sticky="nswe")
    
    app = App()
    app.mainloop()

     

  19. بتاريخ 2 ساعة قال Ahmed Elmrsawy:

    و عليكم السلام ,

    يظهر أن الخطأ ينبع من حقيقة أن الطريقة sht معرفة داخل دالة __init__ في class Frame1، ويتم محاولة الوصول إليها كما لو كانت سمة. لحل هذا، يجب عليك تحديد sht كطريقة للclass بحيث يمكن الوصول إليها باستخدام self.sht().

    إليك class Frame1 المعدل:
     

    import customtkinter
    from tkinter import filedialog
    from pathlib import Path
    import pandas as pd
    
    class Frame1(customtkinter.CTkFrame):
        def __init__(self, master):
            super().__init__(master)
            self.AS = None
    
            def LoadFile():
                filepath = filedialog.askopenfilename(initialdir="C:\\Users\\Cakow\\PycharmProjects\\Main", title="Open file okay?", filetypes=(("text files", "*.xlsx"), ("all files", "*.*")))
                filepathA = Path(filepath)
                self.AS = pd.ExcelFile(filepathA)
                
                AD = self.sht()
                self.optionmenu1.values = AD
    
            self.button1 = customtkinter.CTkButton(self, text="إختيار ملف", font=customtkinter.CTkFont(family="Calibri", size=12, weight="bold"), command=LoadFile)
            self.button1.grid(row=0, column=1, padx=3, pady=(3, 0), sticky="we")
    
            self.optionmenu1 = customtkinter.CTkOptionMenu(self)
            self.optionmenu1.grid(row=0, column=0, padx=3, pady=(3, 0), sticky="we")
    
        def sht(self):
            if self.AS:
                AD = self.AS.sheet_names
                return AD
            else:
                return []
    
    class Frame2(customtkinter.CTkFrame):
        def __init__(self, master):
            super().__init__(master)
            self.checkbox_1 = customtkinter.CTkCheckBox(self, text="checkbox 1")
            self.checkbox_1.grid(row=0, column=0, padx=3, pady=(3, 0), sticky="w")
    
    class Frame3(customtkinter.CTkFrame):
        def __init__(self, master):
            super().__init__(master)
    
            def button_event():
                print("خروج")
    
            self.button2 = customtkinter.CTkButton(self, text="خروج", state="disabled", font=customtkinter.CTkFont(family="Calibri", size=12, weight="bold"), command=button_event)
            self.button2.grid(row=0, column=0, padx=3, pady=(3, 0), sticky="w")
    
    class App(customtkinter.CTk):
        def __init__(self):
            super().__init__()
    
            self.title("my app")
            self.geometry("400x180")
            self.grid_columnconfigure(0, weight=1)
            self.grid_rowconfigure(0, weight=1)
            customtkinter.set_appearance_mode("dark")
            customtkinter.set_default_color_theme("dark-blue")
    
            self.Frame_A = Frame1(self)
            self.Frame_A.grid(row=0, column=0, padx=1, pady=(1, 0), sticky="nswe")
            self.Frame_B = Frame2(self)
            self.Frame_B.grid(row=0, column=1, padx=1, pady=(1, 0), sticky="nswe")
            self.Frame_C = Frame3(self)
            self.Frame_C.grid(row=1, column=0, padx=1, pady=(1, 10), sticky="nswe")
    
    app = App()
    app.mainloop()

     

    الآن، تم تحديد sht كطريقة داخل class Frame1، ويجب أن يمكن الوصول إليها دون أي خطأ في السمة.

    صحيح أخي لقد قمت بإزالة الخطأ 

    لاكن السؤال الأن لماذا هذا الكود لم ينفذ

    self.optionmenu1.values = AD

    حيث تبقى القائمة فارغة

  20. السلام عليكم

    الرجاء التتبع وتصحيح هذا الخطأ

    AttributeError: 'Frame1' object has no attribute 'sht'

    import customtkinter
    from tkinter import filedialog
    from pathlib import Path
    import pandas as pd
    
    class Frame1(customtkinter.CTkFrame):
        def __init__(self, master):
            super().__init__(master)
            self.AS = None
    
            def LoadFile():
                filepath = filedialog.askopenfilename(initialdir="C:\\Users\\Cakow\\PycharmProjects\\Main", title="Open file okay?", filetypes=(("text files", "*.xlsx"), ("all files", "*.*")))
                filepathA = Path(filepath)
                self.AS = pd.ExcelFile(filepathA)
                
                
                AD = self.sht()
                self.optionmenu1.values = AD
    
            def sht():
                if self.AS:
                    AD = self.AS.sheet_names
                    return AD
                else:
                    return []
    
            self.button1 = customtkinter.CTkButton(self, text="إختيار ملف", font=customtkinter.CTkFont(family="Calibri", size=12, weight="bold"), command=LoadFile)
            self.button1.grid(row=0, column=1, padx=3, pady=(3, 0), sticky="we")
    
            self.optionmenu1 = customtkinter.CTkOptionMenu(self)
            self.optionmenu1.grid(row=0, column=0, padx=3, pady=(3, 0), sticky="we")
    
    class Frame2(customtkinter.CTkFrame):
        def __init__(self, master):
            super().__init__(master)
            self.checkbox_1 = customtkinter.CTkCheckBox(self, text="checkbox 1")
            self.checkbox_1.grid(row=0, column=0, padx=3, pady=(3, 0), sticky="w")
    
    class Frame3(customtkinter.CTkFrame):
        def __init__(self, master):
            super().__init__(master)
    
            def button_event():
                print("خروج")
    
            self.button2 = customtkinter.CTkButton(self, text="خروج", state="disabled", font=customtkinter.CTkFont(family="Calibri", size=12, weight="bold"), command=button_event)
            self.button2.grid(row=0, column=0, padx=3, pady=(3, 0), sticky="w")
    
    class App(customtkinter.CTk):
        def __init__(self):
            super().__init__()
    
            self.title("my app")
            self.geometry("400x180")
            self.grid_columnconfigure(0, weight=1)
            self.grid_rowconfigure(0, weight=1)
            customtkinter.set_appearance_mode("dark")
            customtkinter.set_default_color_theme("dark-blue")
    
            self.Frame_A = Frame1(self)
            self.Frame_A.grid(row=0, column=0, padx=1, pady=(1, 0), sticky="nswe")
            self.Frame_B = Frame2(self)
            self.Frame_B.grid(row=0, column=1, padx=1, pady=(1, 0), sticky="nswe")
            self.Frame_C = Frame3(self)
            self.Frame_C.grid(row=1, column=0, padx=1, pady=(1, 10), sticky="nswe")
    
    app = App()
    app.mainloop()

     

  21. بتاريخ 1 ساعة قال Ahmed Emad35:

    السلام عليكم من اجل ان تقوم الداله LoadFile بتحميل الملف كما تريد يجب عليك تعدليها للاتي بحيث  تقوم باستدعاء الدالة sht للحصول على أسماء الأوراق وتحديث قيم OptionMenu بأسماء الأوراق هذه.

    import customtkinter
    from tkinter import filedialog
    from pathlib import Path
    import pandas as pd
    
    class Frame1(customtkinter.CTkFrame):
        def __init__(self, master):
            super().__init__(master)
            self.AS = None
    
            def LoadFile():
                filepath = filedialog.askopenfilename(initialdir="C:\\Users\\Cakow\\PycharmProjects\\Main", title="Open file okay?", filetypes=(("text files", "*.xlsx"), ("all files", "*.*")))
                filepathA = Path(filepath)
                self.AS = pd.ExcelFile(filepathA)
                
                
                AD = self.sht()
                self.optionmenu1.values = AD
    
            def sht():
                if self.AS:
                    AD = self.AS.sheet_names
                    return AD
                else:
                    return []
    
            self.button1 = customtkinter.CTkButton(self, text="إختيار ملف", font=customtkinter.CTkFont(family="Calibri", size=12, weight="bold"), command=LoadFile)
            self.button1.grid(row=0, column=1, padx=3, pady=(3, 0), sticky="we")
    
            self.optionmenu1 = customtkinter.CTkOptionMenu(self)
            self.optionmenu1.grid(row=0, column=0, padx=3, pady=(3, 0), sticky="we")
    
    class Frame2(customtkinter.CTkFrame):
        def __init__(self, master):
            super().__init__(master)
            self.checkbox_1 = customtkinter.CTkCheckBox(self, text="checkbox 1")
            self.checkbox_1.grid(row=0, column=0, padx=3, pady=(3, 0), sticky="w")
    
    class Frame3(customtkinter.CTkFrame):
        def __init__(self, master):
            super().__init__(master)
    
            def button_event():
                print("خروج")
    
            self.button2 = customtkinter.CTkButton(self, text="خروج", state="disabled", font=customtkinter.CTkFont(family="Calibri", size=12, weight="bold"), command=button_event)
            self.button2.grid(row=0, column=0, padx=3, pady=(3, 0), sticky="w")
    
    class App(customtkinter.CTk):
        def __init__(self):
            super().__init__()
    
            self.title("my app")
            self.geometry("400x180")
            self.grid_columnconfigure(0, weight=1)
            self.grid_rowconfigure(0, weight=1)
            customtkinter.set_appearance_mode("dark")
            customtkinter.set_default_color_theme("dark-blue")
    
            self.Frame_A = Frame1(self)
            self.Frame_A.grid(row=0, column=0, padx=1, pady=(1, 0), sticky="nswe")
            self.Frame_B = Frame2(self)
            self.Frame_B.grid(row=0, column=1, padx=1, pady=(1, 0), sticky="nswe")
            self.Frame_C = Frame3(self)
            self.Frame_C.grid(row=1, column=0, padx=1, pady=(1, 10), sticky="nswe")
    
    app = App()
    app.mainloop()

     

    أخي قمت بتجرب الكود الذي قمت حضرتك بتعديله ولاكن لم يعمل 

    لم تدرج الأسماء بالقائمة فأين الخطأ الرجاء أخي التحقق من الكود

    حيث أن الخطأ يظهر هكذا

    AttributeError: 'Frame1' object has no attribute 'sht'

×
×
  • أضف...