The example in this article shows the Python Tkinter method for implementing a simple layout, with a more detailed annotation for the reader to understand. Share for everyone to use for reference. as follows:
#-*-Coding:utf-8-*-from tkinter import * root = Tk () # 80x80 represents the size of the main window at initialization time, 0, 0 represents the location of the window at initialization root.geometry (' 80x80+10 +10 ') # padding Direction ' label (root, Text = ' L1 ', bg = ' red '). Pack (fill = Y) Label (root, Text = ' L2 ', bg = ' green '). Pack (fill = B OTH) label (root, Text = ' L3 ', bg = ' blue '). Pack (fill = X) # Left and right layout Label (root, Text = ' L1 ', bg = ' red '). Pack (fill = Y, sid E = left) label (root, Text = ' L2 ', bg = ' green '). Pack (fill = BOTH, side = right) label (root, Text = ' L3 ', bg = ' Blue '). pac K (fill = X, side = left) # absolute Layout L4 = Label (root, Text = ' L4 ') l4.place (X = 3, y = 3, anchor = NW) ' # grid grid layout L1 = L
Abel (root, Text = ' L1 ', bg = ' red ') L2 = label (root, Text = ' L2 ', bg = ' blue ') L3 = label (root, Text = ' L3 ', bg = ' green ') L4 = label (root, Text = ' L4 ', bg = ' yellow ') L5 = label (root, Text = ' L5 ', bg = ' Purple ') l1.grid (row = 0, column = 0) l
2.grid (row = 1, column = 0) l3.grid (row = 1, column = 1) l4.grid (row = 2) l5.grid (row = 0, column = 3) root.mainloop ()
The grid grid layout works as shown in the following illustration:
Interested readers can test the effect of the example of this article, I believe that the Python program for everyone to have some reference value.