Home > Software design >  Frame of fixed size staying at the bottom of the window
Frame of fixed size staying at the bottom of the window

Time:10-20

I am using Tk GUI and I want my window to be split into 2 frames, something like that:

import tkinter as tk

root = tk.Tk()
root.geometry('1000x800')

df_frame = tk.LabelFrame(root)

df_frame.place(relwidth = 1, height = 720)

open_file_frame = tk.LabelFrame(root)
open_file_frame.place(x = 0, y = 720, relwidth = 1, height = 80)

root.mainloop()

My problem is that I don't know how to make it adaptable to the size of the window. If the user enlarges the size of the window, I want the second frame to stay at the bottom, and the first frame to enlarge accordingly. Thanks in advance for your help.

CodePudding user response:

You can combine relheight and height options to control the height of the top frame.

And combine rely and y options to put the bottom frame at the bottom of the window:

import tkinter as tk

root = tk.Tk()
root.geometry('1000x800')

df_frame = tk.LabelFrame(root)
# frame_height = window_height - 80
df_frame.place(relwidth=1, relheight=1, height=-80)

open_file_frame = tk.LabelFrame(root)
# frame y position = 80 pixel from the bottom
open_file_frame.place(rely=1, y=-80, relwidth=1, height=80)

root.mainloop()
  • Related