Hi there,
First post and totally newbie with Python.
With a lot of help from GPT-4 in Edge i’ve made this folder indexing-tool with a searchbar and checkboxes that should hide and show some listboxes
And this actually works perfectly.
With assistance from GPT-4 in Edge I “just” wanted to integrate it in a toggle window-function so the starting window would be minimize to a preset place on the screen, with a single button. by presssing that button the window should expand to “normal size” known form the fist code attempt.
I can make it work, but then the order of the widgets isn’t correct!
I’d like the Searchbar at the top followed by the checkboxes and then the Listboxes. But “the working attempt of code” loads the listboxes, the searchbar and then the checkboxes.
The idea was as by checking/unchecking the checkboxes; the height of the window gets longer/shorter and only shows the checked listboxes in the correct order.
I don’t know if anybody can figure out a solution in this pretty messy piece of code below!?
If the entire code, is needed I can load this as well.
def toggle_window(state):
if state == "expand":
screen_width = window.winfo_screenwidth()
window.geometry(f"300x700+{screen_width-300}+55")
window.overrideredirect(0)
window.resizable(True, True)
arrowleft_button.pack_forget()
close_button.pack_forget()
arrowright_button.place(relx=0.97, rely=0.005, anchor='ne')
########################
# Load the logo image (ensure the image file is in the same directory as your script)
logo = tk.PhotoImage(file=logo_path)
# Create a label with the logo image
#logo_label = tk.Label(window, image=logo)
logo_label = tk.Label(window, image=logo, borderwidth=0)
logo_label.image = logo # Keep a reference to prevent garbage collection
# Position the label at the lower right corner of the window
logo_label.place(relx=1, rely=1, anchor='se')
########################
# Pack search entry first
search_entry.pack(pady=7)
configure_checkboxes()
# Then pack checkboxes
chk_frame.pack()
# Forget all listboxes and labels
##### for idx in indexes:
##### lb, lbl, var = listboxes[idx]
##### lbl.pack_forget()
##### lb.pack_forget()
# Pack listboxes and labels that are checked in the order of indexes
##### for idx in indexes:
##### lb, lbl, var = listboxes[idx]
##### if var.get():
##### lbl.pack(pady=(8,0)) # Add space above the label
##### lb.pack() # Add space below the listbox
# Update window size
total_height = 150
#lbl.pack_forget()
#lb.pack_forget()
search_entry.pack(pady=7)
chk_frame.pack()
#for index in indexes:
for idx in indexes:
#lb, lbl, var = listboxes[index]
if var.get():
#lbl.pack_forget()
#lb.pack_forget()
# search_entry.pack(pady=7)
# chk_frame.pack()
total_height += lb.winfo_reqheight() + lbl.winfo_reqheight() + 8
lbl.pack(pady=(8,0)) # Add space above the label
lb.pack() # Add space below the listbox
#lb, lbl, var = listboxes[index]
window.geometry(f'300x{total_height}') # Add total height to initial height
lb, lbl, var = listboxes[index]
elif state == "shrink":
window.geometry("38x50-0+55")
window.overrideredirect(1)
arrowright_button.place_forget()
search_entry.pack_forget()
chk_frame.pack_forget() # Forget checkboxes here
# Hide all listboxes and labels
for index in indexes:
lb, lbl, var = listboxes[index]
lbl.pack_forget()
lb.pack_forget()
arrowleft_button.pack(pady=10)
#close_button.pack()
#logo_label.place_forget()
any help appreciated! ![]()
PS. By the way… I’ve also created this post on DEV, but might take it down again, as this community/forum seems more python-related or the right spot for python stuff…?