【问题标题】:python 3.4 tkinter frame does not fill in vertical directionpython 3.4 tkinter帧不填充垂直方向
【发布时间】:2014-12-27 18:59:25
【问题描述】:

我正在制作一个 tkinter 应用程序来查看绘图。我希望窗口在启动时最大化,这很有效。我还想制作一个框架,在其中放置情节及其信息。当我打包框架并尝试使其填充水平和垂直时,它出错了。它确实填充水平,但不填充垂直。在这里搜索答案只会给我带有滚动条的框架。

这是我使用的代码。

from tkinter import *
from tkinter.filedialog import askopenfilename
import tkinter.messagebox as messagebox
import datetime, os

root = Tk()

tl = root.winfo_toplevel()
tl.wm_state('zoomed')

mainframe = Frame(root, bd=1, relief=RAISED, cursor="dotbox")
mainframe.pack(side=TOP, fill=BOTH)    # It only fills horizontal

root.mainloop()

为什么它只填充水平而不是垂直?

【问题讨论】:

    标签: python python-3.x tkinter frame python-3.4


    【解决方案1】:

    您需要传递值大于 0 的 expand option 来告诉包几何管理器为小部件分配额外的空间。

    mainframe.pack(side=TOP, fill=BOTH, expand=1)
    

    否则,小部件将不会展开。


    Pattern - Filling the entire parent widget - The Tkinter Pack Geometry Manager

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-04-14
      • 1970-01-01
      • 1970-01-01
      • 2019-12-20
      • 2010-11-23
      • 2021-06-06
      • 2020-08-11
      相关资源
      最近更新 更多