简体   繁体   中英

How do i place a frame in the bottom right corner of my window?

Im pretty new to programming in python and using tkinter. i want to make a widget, and place it in the bottom right corner of my window, but im unsure of how to place a frame there.

ive made the window fullsscreen and currently have two widgets in the top left corner using grid. Ive spent quite some time trying to find a solution, but most things dont really work as i want them too, or i dont understand whats happening too well

Certainly, it's possible to use grid to make a widget remain at the lower-right corner of the window.

  • First, use rowconfigure and columnconfigure to inform the window which rows and columns should stretch when the window is larger than the total width/height of all grid elements. Assuming you want the other elements of your window to stay where they are, you should weight the column and row your frame resides in.

  • Second, use the sticky argument in grid to inform the frame which edge of the grid it should adhere to when the grid is larger than the frame.

Example:

import tkinter

root = tkinter.Tk()
root.grid_rowconfigure(1, weight=1)
root.grid_columnconfigure(2, weight=1)

a = tkinter.Button(root, text="Reticulate")
b = tkinter.Button(root, text="Frobnicate")

a.grid(row=0, column=0)
b.grid(row=0, column=1)

f = tkinter.Frame(root)
f.grid(row=1, column=2, sticky=tkinter.SE)

g = tkinter.Button(f, text="quit")
g.pack()

root.mainloop()

Result:

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM