الكود الذي قدمته يحتوي على بعض الأخطاء والمشاكل الصغيرة. إليك الكود بعد إجراء بعض التعديلات:
import tkinter as tk
from tkinter import filedialog
from pathlib import Path
import pandas as pd
class App(tk.Tk):
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.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")
self.button = tk.Button(self.Frame_B, text="فتح ملف", font=("Calibri", 12, "bold"), command=self.openFile)
self.button.grid(row=0, column=0, padx=3, pady=(3, 0), sticky="we")
def openFile(self):
filepath = filedialog.askopenfilename(initialdir="C:\\Users\\Cakow\\PycharmProjects\\Main", title="Open file okay?", filetypes=(("text files", "*.xlsx"), ("all files", "*.*")))
filepathA = Path(filepath)
df = pd.read_excel(filepathA, header=None)
class Frame1(tk.Frame):
def __init__(self, master):
super().__init__(master)
self.checkbox_1 = tk.Checkbutton(self, text="checkbox 1")
self.checkbox_1.grid(row=0, column=0, padx=3, pady=(3, 0), sticky="w")
self.checkbox_2 = tk.Checkbutton(self, text="checkbox 2")
self.checkbox_2.grid(row=1, column=0, padx=3, pady=(3, 0), sticky="w")
self.optionmenu = tk.OptionMenu(self, tk.StringVar(), "option 1", "option 2")
self.optionmenu.grid(row=2, column=0, padx=3, pady=(3, 0), sticky="we")
class Frame2(tk.Frame):
def __init__(self, master):
super().__init__(master)
self.optionmenu2 = tk.OptionMenu(self, tk.StringVar(), "Light", "Dark")
self.optionmenu2.grid(row=1, column=0, padx=3, pady=(3, 0), sticky="we")
self.entry1 = tk.Entry(self, font=("Calibri", 12, "bold"), width=20)
self.entry1.grid(row=2, column=0, padx=3, pady=(3, 0), sticky="we")
class Frame3(tk.Frame):
def __init__(self, master):
super().__init__(master)
self.button2 = tk.Button(self, text="تشغيل", font=("Calibri", 12, "bold"), command=self.button_event)
self.button2.grid(row=0, column=0, padx=3, pady=(3, 0), sticky="w")
def button_event(self):
print("button_event")
app = App()
app.mainloop()