Python tkinter layout

Source: Internet
Author: User

Pack layout

The pack function is first used on top, then down in the horizontal position (relative to the parent window)

Pack parameter [ parameter value must be uppercase ]

Side: Where to dock the button in the window

Left: Top: Top, right: Botton: Down

Fill: Fills

X: Horizontal Fill, y: Fill vertically, both: horizontal and vertical, none: not filled

Expand: Whether to extend the white space

Yes: expands the entire white space, no: not extended

Anchor: Location

N: North, E: East Right, S: South, W: Sizo, center: Middle

Margin of padx:x direction

Margin of Pady:y direction

Inner margin of ipadx:x direction

Inner margin of ipady:y direction

 from Import *= Tk () Button (root,text='G'). Pack (anchor=e,padx=20 ) Root.mainloop ()

Grid layout

The grid functions also support such as Ipadx,ipady,padx,pady, which have the same meaning as the pack function, and the default margin is 0;

The grid layout is a grid format, with row for rows and column for columns, and it's worth noting that row and column numbers start at 0.

Grid parameters

Row represents rows

Column represents columns

Sticky: It determines in which direction this component starts.

N: North, E: East Right, S: South, W: West Left

RowSpan: Number of rows across (merged)

ColumnSpan: Number of columns across (merged)

 fromTkinterImport*tk=Tk () var=Intvar ()#Label controls, displaying text and bitmaps, showing in the first lineLabel (tk,text=" First"). Grid (Row=0,sticky=e)#on the rightLabel (tk,text="Second"). Grid (ROW=1,STICKY=W)#second line, left .#Input ControlsEntry (TK). Grid (row=0,column=1,padx=10,pady=10) Entry (TK). Grid (Row=1,column=1)#Multi Box PluginButton=checkbutton (tk,text="Precerve Aspect", variable=var) button.grid (Row=2,columnspan=2,sticky=W)#Insert PicturePhoto=photoimage (file="Wm.png") Label=label (image=photo) Label.grid (Row=0,column=2,rowspan=2,columnspan=2, Sticky=w+e+n+s, padx=5, pady=5)#merge two rows, two columns, center, 5 lengths of Perimeter#Button ControlsButton1=button (tk,text="Zoom in") Button1.grid (Row=2,column=2) Button2=button (tk,text="Zoom out") Button2.grid (Row=2,column=3)#Main Event LoopMainloop ()

Place layout

Place the simplest and most flexible layout, using component coordinates to position the component. But it is not recommended to use, at different resolutions, the interface tends to have a large difference.

Place parameter

Anchor: Location, default value NW same pack layout

X, Y: The x, y-coordinate integer in the upper-left corner of the component, the default value 0 absolute position coordinates, per pixel

Relx, rely: The relative position of floating-point numbers between components relative to the X, y-coordinate 0~1 of the parent container, 0.0 for the left edge (or the top edge), and 1.0 for the right edge (or lower edge)

width, Height: The size of the component, the non-negative integer unit pixels

Relwidth, Relheight: The number of floating-point numbers similar to RELX (rely) between components relative to the parent container's width, height 0~1

Bordermode: If set to INSIDE, the size and position inside the component are relative, excluding the border, and if OUTSIDE, the external size of the component is relative, including the border INSIDE, OUTSIDE (the default INSIDE) can use constants INSIDE, OUTSIDE, you can also use the string form "inside", "OUTSIDE"

 from Import *= Tk () Button (root,text='G'). Place (x=20,y=30,width= 30,height=40,bordermode=INSIDE) root.mainloop ()

Related article: Tkinter layout management of Python GUI

Python tkinter layout

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.