-
Hi, I'm trying to create a dynamic GUI where a variable number of labels, entries and buttons are created based on the content of a specific file. Everything works great except that the main window doesn't auto resize and keeps a fixed size (which seems to be hard coded to 500x600). My window has two frames : one with just a label + entry + button and another one with several rows of label + entry + button. All widgets are placed using the .grid() function. The second frame correctly resize itself based on the number of widgets that are created but not the main window. FYI I'm using customtkinter 4.5.10 and Python 3.10.6. |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 3 replies
-
Ok I've done some tests and tried with just a really simple application with just one frame and several buttons. I've tried the same layout, same code (nothing less, nothing more) but with Tkinter, and in this case the window properly resizes itself. So it really is related to CTk. import tkinter
import customtkinter
class TestAppCTk():
def __init__(self) -> None:
self._window = customtkinter.CTk()
frame = customtkinter.CTkFrame(master=self._window)
frame.grid(row=0, column=0, padx=15, pady=15)
# Create 20 buttons
for btn_idx in range(20):
btn = customtkinter.CTkButton(master=frame)
btn.grid(row=btn_idx, column=0, padx=15, pady=5)
btn.set_text(f"Button {btn_idx}")
class TestAppTk():
def __init__(self):
self._window = tkinter.Tk()
# Create a frame
self._frame = tkinter.Frame(master=self._window)
self._frame.grid(row=0, column=0, padx=15, pady=15)
# Create 20 buttons
for btn_idx in range(20):
btn = tkinter.Button(master=self._frame, text=f"Button {btn_idx}")
btn.grid(row=btn_idx, column=0, padx=15, pady=5)
if __name__ == "__main__":
app = TestAppCTk()
app._window.mainloop()
#app = TestAppTk()
#app._window.mainloop() |
Beta Was this translation helpful? Give feedback.
-
@frwol I got the solution for you, First make a separate frame which will act as the background window (do not use pady or padx). self._window = customtkinter.CTk()
frame = customtkinter.CTkFrame(master=self._window)
frame.grid(row=0, column=0) Create all of your widgets/sub-frames inside that main frame and then add these lines in the end of your code: frame.update_idletasks()
width = frame.winfo_width()
height = frame.winfo_height()
self._window.geometry(f"{width}x{height}") Here is your modified example file |
Beta Was this translation helpful? Give feedback.
-
very good. |
Beta Was this translation helpful? Give feedback.
@frwol I got the solution for you,
First make a separate frame which will act as the background window (do not use pady or padx).
Create all of your widgets/sub-frames inside that main frame and then add these lines in the end of your code:
Here is your modified example file