简体   繁体   中英

Tkinter frame to occupy full bottom row of window

I'm trying to display a window with tkinter that has a frame which occupies the entire bottom row.

Here is the code as I have it now:

import openpyxl, PIL.Image, sys
from tkinter import *

class App(object):
    def __init__(self, root):
        self.root = root
        w, h = root.winfo_screenwidth() * .9, root.winfo_screenheight() * .9
        root.geometry("%dx%d+0+0" % (w, h))

        root.title('Squirrel Project')
        root.wm_iconbitmap('Squirrel.ico')

        buttonFrame = Frame(root, width = w, height = 25, padx = 15, pady = 15, bg = 'blue')
        buttonFrame.pack(fill = X, expand = True, side = BOTTOM)

        saveButton = Button(buttonFrame, text = 'Save', command = self.save).pack(side = LEFT)

With the above code, the frame occupies the entire width of the window, but in the middle row. If I remove fill = X, expand = True from buttonFrame.pack then the frame will occupy the bottom row, but only a portion of it. How can I have the frame occupy the entire bottom row?

You've given the option expand=True , which is telling the frame to take up extra space in the window. Thus, since it's the only thing in the window it uses all of the space in the window.

If you don't want it to take up extra space, omit that option or set it to False .

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