Reputation: 1
How can I achieve a result like this in python Tkinter? I want a window with a main frame whose width takes up 50% of the window's width and, if need be, two side frames of 25% width each.
Here's the simplified code:
from tkinter import *
root = Tk()
root.geometry("100x100")
f1 = Frame(root,bg="white",width=root.winfo_width()//4)
f1.pack()
main = Frame(root,bg="black",width=root.winfo_width()//2)
main.pack()
f2 = Frame(root,bg="white",width=root.winfo_width()//4)
f2.pack()
Why are the frames not showing? Please help!
Bonus point if you can do away with the two side frames
Upvotes: 0
Views: 1868
Reputation: 47193
It can be achieved by using .place()
:
from tkinter import *
root = Tk()
root.geometry("100x100")
main = Frame(root,bg="black")
main.place(relx=0.5, rely=0.5, relwidth=0.5, relheight=1, anchor="c")
root.mainloop()
Upvotes: 3