Why are frames resizing when using python tkinter?

前端 未结 1 983
终归单人心
终归单人心 2021-01-28 22:36

My code is the following:

import tkinter as tk

#setting up window.
root = tk.Tk()
root.title(\"CSV Maker\")
root.geometry(\"600x300\")

#setting up frames.
left         


        
相关标签:
1条回答
  • 2021-01-28 23:05

    That is simply how tkinter was designed to work. When you use pack or grid, frames (or any other widget) will shrink or expand to try to fit all of its contents.

    99.9% of the time, this is the behavior you want. Tkinter is really good at making GUIs the appropriate size.

    From the official documentation for grid:

    The grid geometry manager normally computes how large a master must be to just exactly meet the needs of its slaves, and it sets the requested width and height of the master to these dimensions. This causes geometry information to propagate up through a window hierarchy to a top-level window so that the entire sub-tree sizes itself to fit the needs of the leaf windows. However, the grid propagate command may be used to turn off propagation for one or more masters. If propagation is disabled then grid will not set the requested width and height of the master window. This may be useful if, for example, you wish for a master window to have a fixed size that you specify.

    From the documentation for pack:

    The packer normally computes how large a master must be to just exactly meet the needs of its slaves, and it sets the requested width and height of the master to these dimensions. This causes geometry information to propagate up through a window hierarchy to a top-level window so that the entire sub-tree sizes itself to fit the needs of the leaf windows. However, the pack propagate command may be used to turn off propagation for one or more masters. If propagation is disabled then the packer will not set the requested width and height of the packer. This may be useful if, for example, you wish for a master window to have a fixed size that you specify.

    Notice that place doesn't have the same behavior. From the place documentation:

    Unlike many other geometry managers (such as the packer) the placer does not make any attempt to manipulate the geometry of the master windows or the parents of slave windows (i.e. it does not set their requested sizes). To control the sizes of these windows, make them windows like frames and canvases that provide configuration options for this purpose.

    0 讨论(0)
提交回复
热议问题