Closed P3rdigas closed 4 months ago
The issue is here:widget.delete(0, END)
. The misunderstanding is that widget.delete(0, END)
is used by the vanilla tkinter library, customtkinter utilizes widget.delete(first_index, last_index)
to delete the whole data inside an entry you can use widget.delete(0, len(widget.get()))
So instead of using the above code use this:
frame_widgets = self.data_entry_scroll_frame.winfo_children()
for widget in frame_widgets:
row_index = widget.grid_info()["row"]
col_index = widget.grid_info()["column"]
if row_index > 3 or col_index > 2:
if type(widget) != customtkinter.CTkButton:
widget.destroy()
else:
if type(widget) == customtkinter.CTkEntry:
widget.delete(0, len(widget.get()))
num_cols = self.data_entry_scroll_frame.grid_size()[0]
num_rows = self.data_entry_scroll_frame.grid_size()[1]
print(f"Num_Cols: {num_cols} Num_Rows: {num_rows}")
I think i made a mistake when i wrote this issue, i wanna clear (delete the string) of some entries and the destroy the rest of them. The deletion of the data inside the Entries works, so i assume the issue occurs when i try to destroy the entries. I forgot to include that the const END was imported from tkinter(from tkinter import filedialog, END
).
This is a look when i import the file and the data is populated:
Now, after deleting the file, the entries are cleared and the rest are destroyed visually, like:
However, with the code above, the result of the grid is: Num_Cols: 7 Num_Rows: 22
Oh, so this is better plus I didn't know that you were importing the delete function from tkinter. Sorry for that.
so according to your given code I cam up with this:
frame_widgets = self.data_entry_scroll_frame.winfo_children()
for widget in frame_widgets:
row_index = widget.grid_info()["row"]
col_index = widget.grid_info()["column"]
if row_index > 3 or col_index > 2:
if not isinstance(widget, customtkinter.CTkButton):
widget.destroy()
else:
if isinstance(widget, customtkinter.CTkEntry):
widget.delete(0, len(widget.get()))
num_cols = self.data_entry_scroll_frame.grid_size()[0]
num_rows = self.data_entry_scroll_frame.grid_size()[1]
print(f"Num_Cols: {num_cols} Num_Rows: {num_rows}")
Try this and lemme know! Or maybe add a bigger code or simply send a link of your GITHUB repo we'll take a look at it
Unfornately that code doesn't seem to fix it. Here is the link of my repo https://github.com/P3rdigas/AutoContract. For the frame i'm using a third party libary, CTkXYFrame, found here: https://github.com/Akascape/CTkXYFrame. Initially i suspected that the issue was related with the grid layout, but i'm testing if the issue could be related with the CTkXYFrame library, but if you found any issue with my code let me know!
I think i found the issue. The buttons for adding columns and rows have a property of rowspan and columnspan. When the data is imported these properties are updated. My problem was that i wanted to update these properties with the size of the grid, however the grid size is influenced by them, meaning that when data is imported the columnspan is updated to 21 and the rowspan to 7. When the entries are destroyed these properties are not updated and the grid size remain 7 and 21, but if inside the for loop i set the columnspan and rowspan of the buttons to 1, in the end the real size of the grid will be shown. Thanks a lot for your time and your help!
I'm doing an app using this library where the user can load an file and that will populate CTkEntries inside a frame in a grid layout. However, when the user delete the files, i wanna clear the text inside the Entries and delete the extra ones, but the size of the grid is not updated.
Code:
Result: Num_Cols: 7 Num_Rows: 22