1. Minimum interface composition
# Import module tkinter Import tkinter # Create main window object the root = tkinter.Tk () # Set Window Size (Min: pixels) root.minsize (300,300 ) # Create a button component BTN = tkinter.Button (the root, text = ' Dragon sword, click send ' ) btn.pack () # join message loop root.mainloop ()
2. components Display mode:
1.pack () mode -> direction / orientation of the display method
2.grid () mode -> grid display pattern
3.place () mode -> Location display method
3.pack layout Introduction
pack () method:
disposed side assembly relative to the parent component placement
# Import module tkinter Import tkinter # Create main window object the root = tkinter.Tk () # Set Window Size (Min: pixels) root.minsize (500,500 ) # Create a button component btn0 = tkinter.Button (the root, text = ' button 1 ' ) # default above or = Side' Top ' btn0.pack () btn1 = tkinter.Button (the root, text = ' button 1 ' ) # following btn1.pack (Side = ' bottom ' ) btn2 = tkinter.Button (the root, text = ' button 2 ' ) # left btn2.pack (Side = ' left ' ) btn3 = tkinter.Button (the root, text = ' button 2 ' ) # the right btn3.pack (Side = ' right ' ) # join message loop root.mainloop ()
ipadx, ipady assembly disposed inside the pitch
= tkinter.Button btn0 (the root, text = ' button 1 ' ) # setting button text-to-edge spacing btn0.pack (ipadx = 20, ipady = 20)
padx, pady plurality of components disposed external spacing
= tkinter.Button btn0 (the root, text = ' button 1 ' ) # external components disposed around padx pitch, pady assembly disposed outside the vertical spacing btn0.pack (padx = 20, pady = 20)
fill set button station or a line
btn1 = tkinter.Button (root, text = ' click send Dragon sword!')
# of the assembly station of the maximum horizontal position
btn.pack (Fill = 'X')
btn2 = tkinter.Button (the root, text = ' Dragon sword click send! ')
# maximum vertical position of the assembly station, but must be side =' right 'or' left 'take effect
btn2.pack (fill =' y ', side =' right ')
expand set side is invalid
= tkinter.Button btn1 (the root, text = ' Dragon sword click send! ' ) # Yes failure side when the button is located in the middle of the window, all horizontal and vertical button occupied space, this time all of the space station fill = both buttons btn1 .pack (the expand = ' Yes ' , Fill = ' both ' )
Note: only use the pack can not be achieved in tabular form, requires the help of Franme components can be achieved only very complicated.
grid () mode
Set the default number of rows row 0
column to set the number of columns defaults to 0
= tkinter.Button btn1 (the root, text = ' button. 1 ' ) btn1.grid () btn2 = tkinter.Button (the root, text = ' button 2 ' ) btn2.grid (Row =. 1, column =. 1) # Set button position btn3 = tkinter.Button (the root, text = ' button. 3 ' ) btn3.grid (Row = 0, column =. 1)
rowspan set the number of interbank
cloumnspan set the number of columns across
ipadx, ipady component sizes provided
= tkinter.Button btn1 (the root, text = ' button. 1 ' ) btn1.grid () btn2 = tkinter.Button (the root, text = ' button 2 ' ) btn2.grid (Row =. 1, column = 0) # Set button position btn2 = tkinter.Button (the root, text = ' button 2 ' ) btn2.grid (Row = 0, column = 2, rowspan = 2, ipady * 2 = 15 ) btn2 = tkinter.Button (the root, text = ' button 2 ' ) btn2.grid (Row = 2, column = 0, = ColumnSpan. 3, 20 is ipadx =)