0

I coded a simple ttkbootstrap/tkinter application that contains 4 Frames that divides the "root" window in 4 and added a simple button and a Text widget.

Here's the code:

import ttkbootstrap as ttk

root = ttk.Window(themename="darkly")
root.geometry("800x600")
root.columnconfigure([0,1,2,3,4,5,6,7,8,9], weight= 1, uniform="a")
root.rowconfigure([0,1,2,3,4,5,6,7,8,9], weight= 1, uniform="a")

#Creating Frames
frame1 = ttk.Frame(root, style="dark")
frame1.grid(row=0, column=0, columnspan=5, rowspan=5,sticky="nswe")
frame1.columnconfigure([0,1,2,3,4,5], weight=1, uniform="a")
frame1.rowconfigure([0,1,2,3,4,5], weight=1, uniform="a")

frame2 = ttk.Frame(root, style="light")
frame2.grid(row=0, column=5, columnspan=5,rowspan=5, sticky="nswe")
frame2.columnconfigure([0,1,2,3,4,5], weight=1, uniform="a")
frame2.rowconfigure([0,1,2,3,4,5], weight=1, uniform="a")

frame3 = ttk.Frame(root, style="light")
frame3.grid(row=5, column=0, columnspan=5, rowspan=5, sticky="nswe")
frame3.columnconfigure([0,1,2,3,4,5], weight=1, uniform="a")
frame3.rowconfigure([0,1,2,3,4,5], weight=1, uniform="a")

frame4 = ttk.Frame(root, style="dark")
frame4.grid(row=5, column=5, columnspan=5, rowspan=5, sticky="nswe")
frame4.columnconfigure([0,1,2,3,4,5], weight=1, uniform="a")
frame4.rowconfigure([0,1,2,3,4,5], weight=1, uniform="a")

#Widgets
start_button = ttk.Button(frame1, text="Start", bootstyle="default", command=start_app)
start_button.grid(row=1, column=0, columnspan=2, sticky="nswe")

texto = ttk.Text(root, wrap="word",width=1,height=1, font=("Helveltica", 12))
texto.grid(row=2, column=0, columnspan=3,rowspan=1 ,sticky="nswe")
texto.insert(index=ttk.END, chars="hello world")

scroll_y = ttk.Scrollbar(root, orient=ttk.VERTICAL, command=texto.yview, style="light")
scroll_y.grid(row=2, column=3,rowspan=1,sticky="wsn")
texto.config(yscrollcommand=scroll_y)
texto["yscrollcommand"] = scroll_y.set

root.mainloop()

Looks good.

Looks normal

But when I set the master of the texto instance to frame1, the whole layout gets messed up.

Messed layout

This is the code after changes

texto = ttk.Text(frame1, wrap="word",width=1,height=1, font=("Helveltica", 12))
texto.grid(row=2, column=0, columnspan=3,rowspan=1 ,sticky="nswe")
texto.insert(index=ttk.END, chars="hello world")

scroll_y = ttk.Scrollbar(frame1, orient=ttk.VERTICAL, command=texto.yview, style="light")
scroll_y.grid(row=2, column=3,rowspan=1,sticky="wsn")
texto.config(yscrollcommand=scroll_y)
texto["yscrollcommand"] = scroll_y.set

Does anyone know why this happens, and how to fix it? I need them to stop resizing. Even when I set the master to root it can produce some strange behaviour, and screw all the frame positioning.

Tried changing the master to frame1 and my layout got messy and uneven. I need them to stop resizing.

1
  • 1
    It's doing exactly what you told it to - frame1 has 5 rows, which you have constrained to all be the same height, but you've only put widgets in two of those rows. Whichever one is tallest (not sure if this is the Text or the Scrollbar) sets the uniform row height, and therefore the Frame is necessarily five times as tall. (I think you're misunderstanding grid rows and columns, anyway - each container has its own, entirely independent grid system. The fact that each Frame contains five rows does not mean that they have to occupy anything more than a single row in the root window.) Commented Jul 19, 2024 at 1:01

1 Answer 1

0

How I understand it you have to think as each frame as an individual layer. Hou have the root layer on which you want to add four frames: 2x2 (row and columns: [0,1]) inside the frames you are starting from new to count. Try the following code: Ijust added the start_app command so that there is no error with the texto command...

import ttkbootstrap as ttk

def start_app():
    pass


root = ttk.Window(themename="darkly")
root.geometry("800x600")
root.columnconfigure([0,1], weight= 1, uniform="a")
root.rowconfigure([0,1], weight= 1, uniform="a")

#Creating Frames
frame1 = ttk.Frame(root, style="dark")
frame1.grid(row=0, column=0, sticky="nswe")
frame1.columnconfigure([0,1,2,3,4,5], weight=1, uniform="a")
frame1.rowconfigure([0,1,2,3,4,5], weight=1, uniform="a")

frame2 = ttk.Frame(root, style="light")
frame2.grid(row=0, column=1, sticky="nswe")
frame2.columnconfigure([0,1,2,3,4,5], weight=1, uniform="a")
frame2.rowconfigure([0,1,2,3,4,5], weight=1, uniform="a")

frame3 = ttk.Frame(root, style="light")
frame3.grid(row=1, column=0, sticky="nswe")
frame3.columnconfigure([0,1,2,3,4,5], weight=1, uniform="a")
frame3.rowconfigure([0,1,2,3,4,5], weight=1, uniform="a")

frame4 = ttk.Frame(root, style="dark")
frame4.grid(row=1, column=1, sticky="nswe")
frame4.columnconfigure([0,1,2,3,4,5], weight=1, uniform="a")
frame4.rowconfigure([0,1,2,3,4,5], weight=1, uniform="a")

#Widgets
start_button = ttk.Button(frame1, text="Start", bootstyle="default", command=start_app)
start_button.grid(row=1, column=0, columnspan=2, sticky="nswe")

texto = ttk.Text(frame1, wrap="word",width=1,height=1, font=("Helveltica", 12))
texto.grid(row=2, column=0, columnspan=3,rowspan=1 ,sticky="nswe")
texto.insert(index=ttk.END, chars="hello world")

scroll_y = ttk.Scrollbar(frame1, orient=ttk.VERTICAL, command=texto.yview, style="light")
scroll_y.grid(row=2, column=3,rowspan=1,sticky="wsn")
texto.config(yscrollcommand=scroll_y)
texto["yscrollcommand"] = scroll_y.set

root.mainloop()
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.