The geometry manager of the "Python Basics" Tkinter

Source: Internet
Author: User

Tkinter supports three kinds of geometry managers: Grid Manager, Package Manager, location Manager

Tip: Because each manager has its own style of placing widgets, it is best not to use multiple managers in small artifacts in the same container. You can use the framework as a sub-container to get the desired layout.

1. Grid Manager
#Geometry Manager (1)-----grid Manager" "The grid manager places the widget in each cell that is not visible to the grid. You can place widgets in a specific row and column, or you can use the rowspan and ColumnSpan parameters to place widgets in multirow and multiple columns. " " fromTkinterImport*classGridmanagerdemo:window=Tk () window.title ("Grid Manager Demo") Message= Message (window, Text ="This Message widget occupies three rows and columns") Message.grid (Row= 1, column = 1, rowspan = 3, ColumnSpan = 2) Label (window, text="First Name:"). Grid (row = 1, column = 3) Entry (window). Grid (Row= 1, column = 4, PADX = 5, Pady = 5) Label (window, text="Last Name:"). Grid (row = 2, column = 3) Entry (window). Grid (Row= 2, column = 4) Button (window, text="Get Name"). Grid (row = 3, PADX = 5, Pady = 5,column = 4, sticky =E) Window.mainloop () Gridmanagerdemo ()

2. Package Manager
#Geometry Manager (2)-----Package Manager" "The include manager places the widget in one place on top of another or places them one next to the other. " "#First Kind fromTkinterImport*classPackmanagerdemo:def __init__(self): Window=Tk () window.title ("Pack mananger Demo 1") Label (window, text="Blue", bg="Blue"). Pack ()#Fill fills a horizontal, vertical, or two-directional space by X,y,both        #Expand tells the manager to allocate extra space to the widgetLabel (window, Text ="Red", BG ="Red"). Pack (fill = BOTH, expand = 1) Label (window, text="Green", BG ="Green"). Pack (fill =BOTH) Window.mainloop () Packmanagerdemo ()#The second KindclassPackmanagerdemowithside:window=Tk () window.title ("Pack Manager Demo 2")    #side can be left, right, top, BOTTOM, default is top. Label (window, Text ="Blue", bg="Blue"). Pack (side =Left ) Label (window, text="Red", BG ="Red"). Pack (side = left, fill = BOTH, expand = 1) Label (window, text="Green", BG ="Green"). Pack (side = left, fill =BOTH) Window.mainloop () packmanagerdemowithside ()

3. Location Manager
#Geometry Manager (3)-----Location Manager" "The location manager places the widget in an absolute position. " " fromTkinterImport*classPlacemanagerdemo:def __init__(self): Window=Tk () window.title ("Place Manager Demo") Label (window, text="Blue", BG ="Blue"). place (x = $, y = 20) Label (window, text="Red", BG ="Red"). place (x = 50, y =) Label (window, text="Green", BG ="Green"). place (x = A, y = 80) Window.mainloop () Placemanagerdemo ()



Python Basics Tkinter Geometry manager

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.