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 ()
20170104 End
The geometry manager of the "Python Basics" Tkinter