0

I'm making a data entry form. I added two frames inside third_frame variable,

third_frame = customtkinter.CTkFrame(app)
third_frame.grid_columnconfigure((0,1), weight=1)

The third_frame_tabel inside third_frame variable was the second indexed frame,

third_frame_tabel = customtkinter.CTkFrame(third_frame, corner_radius=0)
third_frame_tabel.grid(row=0, column=1)

Now, when i add a table inside third_frame_tabel,

value = [[1,2,3,4,5],
         [1,2,3,4,5],
         [1,2,3,4,5],
         [1,2,3,4,5],
         [1,2,3,4,5]]

table = CTkTable(third_frame_tabel, row=5, column=5, values=value).grid(row=0, column=0)

it overlaps first frame inside main frame(third_frame), and also when I resize my app window, the proportion between both is not equal. Problem solves when I give table a fix width but then it does not remain responsive. Any idea how to solve this problem? You can copy and run the code if you have libraries installed.

Apart from this, if anyone knows how to add buttons or checkboxes inside table, please give me suggestions as I also want Edit and Delete button with table's each row. I tried to do this earlier but failed.

Full source code.

import customtkinter
import customtkinter
from CTkTable import *

# Create App
app = customtkinter.CTk()
app.title("image_example.py")
app.geometry("700x450")

# Set grid layout 1x2
app.grid_rowconfigure(0, weight=1)
app.grid_columnconfigure(1, weight=1)

# Load images with light and dark mode image
# image_path = os.path.join(os.path.dirname(os.path.realpath(__file__)), "test_images")
# logo_image = customtkinter.CTkImage(Image.open(os.path.join(image_path, "CustomTkinter_logo_single.png")), size=(26, 26))
# large_test_image = customtkinter.CTkImage(Image.open(os.path.join(image_path, "large_test_image.png")), size=(500, 150))
# image_icon_image = customtkinter.CTkImage(Image.open(os.path.join(image_path, "image_icon_light.png")), size=(20, 20))
# home_image = customtkinter.CTkImage(light_image=Image.open(os.path.join(image_path, "home_dark.png")),
#                                      dark_image=Image.open(os.path.join(image_path, "home_light.png")), size=(20, 20))
# chat_image = customtkinter.CTkImage(light_image=Image.open(os.path.join(image_path, "chat_dark.png")),
#                                      dark_image=Image.open(os.path.join(image_path, "chat_light.png")), size=(20, 20))
# add_user_image = customtkinter.CTkImage(light_image=Image.open(os.path.join(image_path, "add_user_dark.png")),
#                                          dark_image=Image.open(os.path.join(image_path, "add_user_light.png")), size=(20, 20))

# Create navigation frame
navigation_frame = customtkinter.CTkFrame(app, corner_radius=0)
navigation_frame.grid(row=0, column=0, sticky="nsew")
navigation_frame.grid_rowconfigure(4, weight=1)

navigation_frame_label = customtkinter.CTkLabel(navigation_frame, text="  Image Example",
                                                 compound="left", font=customtkinter.CTkFont(size=15, weight="bold"))
navigation_frame_label.grid(row=0, column=0, padx=20, pady=20)

home_button = customtkinter.CTkButton(navigation_frame, corner_radius=0, height=40, border_spacing=10, text="Home",
                                       fg_color="transparent", text_color=("gray10", "gray90"), hover_color=("gray70", "gray30"),
                                        anchor="w")
home_button.grid(row=1, column=0, sticky="ew")

frame_2_button = customtkinter.CTkButton(navigation_frame, corner_radius=0, height=40, border_spacing=10, text="Frame 2",
                                         fg_color="transparent", text_color=("gray10", "gray90"), hover_color=("gray70", "gray30"),
                                          anchor="w")
frame_2_button.grid(row=2, column=0, sticky="ew")

frame_3_button = customtkinter.CTkButton(navigation_frame, corner_radius=0, height=40, border_spacing=10, text="Frame 3",
                                         fg_color="transparent", text_color=("gray10", "gray90"), hover_color=("gray70", "gray30"),
                                         anchor="w")

frame_3_button.grid(row=3, column=0, sticky="ew")

appearance_mode_menu = customtkinter.CTkOptionMenu(navigation_frame, values=["Light", "Dark", "System"])
appearance_mode_menu.grid(row=6, column=0, padx=20, pady=20, sticky="s")

# Create home frame
home_frame = customtkinter.CTkFrame(app, corner_radius=0, fg_color="transparent")
home_frame.grid_columnconfigure(0, weight=1)


# Create second frame
second_frame = customtkinter.CTkFrame(app, corner_radius=0, fg_color="transparent")

# Create third frame
third_frame = customtkinter.CTkFrame(app)
third_frame.grid_columnconfigure((0,1), weight=1)

third_frame_dataEntry = customtkinter.CTkFrame(third_frame, corner_radius=0)
third_frame_dataEntry.grid(row=0, column=0, sticky="nsew")
third_frame_dataEntry.grid_columnconfigure(0, weight=1)
third_frame_dataEntry.grid_columnconfigure(1, weight=4)

customtkinter.CTkLabel(third_frame_dataEntry, text='Student ID', anchor='w').grid(row=0, column=0, padx=(10,5), pady=(10, 5), sticky='nsew')
customtkinter.CTkEntry(third_frame_dataEntry).grid(row=0, column=1, padx=(5,10), pady=(10, 5), sticky='w')

customtkinter.CTkLabel(third_frame_dataEntry, text='Student Name', anchor='w').grid(row=1, column=0, padx=(10,5), pady=5, sticky='nsew')
customtkinter.CTkEntry(third_frame_dataEntry).grid(row=1, column=1, padx=(5,10), pady=5, sticky='nsew')

customtkinter.CTkLabel(third_frame_dataEntry, text='Father Name', anchor='w').grid(row=2, column=0, padx=(10,5), pady=5, sticky='nsew')
customtkinter.CTkEntry(third_frame_dataEntry).grid(row=2, column=1, padx=(5,10), pady=5, sticky='nsew')

customtkinter.CTkLabel(third_frame_dataEntry, text='Select Class', anchor='w').grid(row=3, column=0, padx=(10,5), pady=5, sticky='nsew')
customtkinter.CTkOptionMenu(third_frame_dataEntry, values=["option 1", "option 2"]).grid(row=3, column=1, padx=(5,10), pady=5, sticky="nsew")
# , command=sidebar_button_event
customtkinter.CTkButton(third_frame_dataEntry, text='Add').grid(row=4, column=1, sticky="e", padx=10, pady=10)


third_frame_tabel = customtkinter.CTkFrame(third_frame, corner_radius=0)
third_frame_tabel.grid(row=0, column=1)

value = [[1,2,3,4,5],
         [1,2,3,4,5],
         [1,2,3,4,5],
         [1,2,3,4,5],
         [1,2,3,4,5]]

table = CTkTable(third_frame_tabel, row=5, column=5, values=value).grid(row=0, column=0)


def set_frame_by_name(selected_frame):
    home_button.configure(fg_color=("gray75", "gray25") if selected_frame == "home" else "transparent")
    frame_2_button.configure(fg_color=("gray75", "gray25") if selected_frame == "frame_2" else "transparent")
    frame_3_button.configure(fg_color=("gray75", "gray25") if selected_frame == "frame_3" else "transparent")

    home_frame.grid_forget()
    second_frame.grid_forget()
    third_frame.grid_forget()

    if selected_frame == "home":
        home_frame.grid(row=0, column=1, sticky="nsew")
    elif selected_frame == "frame_2":
        second_frame.grid(row=0, column=1, sticky="nsew")
    elif selected_frame == "frame_3":
        third_frame.grid(row=0, column=1, sticky="nsew", padx=10, pady=10)



def change_appearance_mode_event(new_appearance_mode):
    customtkinter.set_appearance_mode(new_appearance_mode)

set_frame_by_name('home')
home_button.configure(command = lambda: set_frame_by_name('home'))
frame_2_button.configure(command = lambda: set_frame_by_name('frame_2'))
frame_3_button.configure(command = lambda: set_frame_by_name('frame_3'))
appearance_mode_menu.configure(command=change_appearance_mode_event)
set_frame_by_name('frame_3')

# Start the main loop
app.mainloop()

3
  • I don't see anything about TreeView in your code. It seems you're trying to implement Tabs. Take a look at ttk.Notebook. Also try to provide a minimal reproducible example and focus on the actual problem you're facing.
    – Tranbi
    Nov 20 at 12:30
  • Sorry, I missed to mention the Table code while stating the pr written there in the (All source code). I edited the question and mentioned the Table code now. So now you can check. Nov 20 at 15:08
  • Use app.minsize(700, 450) instead of app.geometry(...).
    – acw1668
    Nov 20 at 15:23

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.