简体   繁体   English

Tkinter框架占据了窗口的全部底部行

[英]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. 我正在尝试显示带有tkinter的窗口,该窗口的框架占据整个底部行。

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. 如果我从buttonFrame.pack删除fill = X, expand = True ,则该框架将占据底部一行,但仅占据其中一部分。 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. 您已经提供了expand=True选项,它告诉框架占用窗口中的额外空间。 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 . 如果您不希望它占用额外的空间,请忽略该选项或将其设置为False

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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