Collapsing Frames #2608
Replies: 2 comments 4 replies
-
Please describe your problem more clearly. Also, any visual attachment would be helpful. |
Beta Was this translation helpful? Give feedback.
-
I did not find anything wrong with the code you provided and you described it. I tested canceling the box from window and from button but the Is there anything else you want to be tested? Or could you please provide a video demonstration of your problem what you are experiencing and expecting? Here is your updated code I used to place items on second (on the right side) frame: import customtkinter as ctk
from CTkMessagebox import CTkMessagebox
from tkinter import filedialog
class Frame1(ctk.CTkFrame):
def __init__(self, master, **kwargs):
super().__init__(master, **kwargs)
self.grid_columnconfigure(0, weight=1)
self.grid_rowconfigure(0, weight=1)
self.button1 = ctk.CTkButton(self, text="Import CSV", command=self.import_file)
self.button1.grid(row=2, column=0, padx=10, pady=10, sticky="ew")
def import_file(self):
file_path = filedialog.askopenfilename(
title="Select Statement CSV",
filetypes=[("CSV Files", "*.csv")]
)
if not file_path:
CTkMessagebox(title="Error", message="Please select a CSV file.", icon='cancel')
# if hasattr(self.master, 'frame2'):
# self.master.frame2.destroy() # Destroy the old frame2 if it exists
# self.master.frame2 = Frame2(self.master) # Recreate Frame2
# self.master.frame2.grid(row=0, column=1, padx=10, pady=10, sticky="nsew")
# self.master.frame2.update()
# self.master.frame2.lift()
return
else:
with open(file_path, "r") as file:
file_data = file.read()
columns = file_data.split(",")
for col in columns:
ctk.CTkLabel(self.frame2_ref, text=col, fg_color="darkgreen", corner_radius=20).pack(side="left")
class Frame2(ctk.CTkFrame):
def __init__(self, master, **kwargs):
super().__init__(master, **kwargs)
self.grid_rowconfigure(0, weight=1)
self.grid_columnconfigure(0, weight=1)
class App(ctk.CTk):
def __init__(self):
super().__init__()
ctk.set_appearance_mode('dark')
self.title('Test')
self.geometry("700x400")
self.grid_columnconfigure([0, 1], weight=1)
self.grid_rowconfigure(0, weight=1)
self.frame1 = Frame1(self)
self.frame1.grid(row=0, column=0, padx=10, pady=10, sticky="nsew")
self.frame1.grid_propagate(False)
self.frame2 = Frame2(self)
self.frame2.grid(row=0, column=1, padx=10, pady=10, sticky="nsew")
self.frame2.grid_propagate(False)
self.frame1.frame2_ref = self.frame2
if __name__ == "__main__":
app = App()
app.mainloop() Please feel free to discuss further problems, |
Beta Was this translation helpful? Give feedback.
-
Hi, fantastic GUI package.
I'm having issues with Frames collapsing/disappearing when I use certain functions from Tkinter. I'm an amateur programmer learning GUIs with Python as an extra for grad school. Below, there is an example code of the problem I encountered. When I click the button to prompt the import dialogue, but I cancel instead of selecting it and repeat the process, Frame 2 collapses. Commented, I added the tweak I found to go around this problem, but I guess this is not efficient when I have multiple Frames and Tkinter functionalities.
Is there a more efficient solution?
Beta Was this translation helpful? Give feedback.
All reactions