This article Reprinted from: http://blog.csdn.net/jcodeer/article/details/1811339
'''Tkinter: frame '''
# Frame is a rectangular area on the screen. It is mostly used as a container to layout the form.
'''1. Create a frame '''
#-*-Coding: cp936 -*-
From tkinter import *
Root = TK ()
# Differentiate frames by different colors
For FM in ['red', 'Blue ', 'yellow', 'green', 'white', 'black']:
# Note that the method for creating a frame is different from the method for creating other controls. The first parameter is not root.
Frame (Height = 20, width = 400, BG = FM). Pack ()
Root. mainloop ()
# Add frames of different colors. The size is 20*400.
'''2. Add a widget to the frame '''
#-*-Coding: cp936 -*-
From tkinter import *
Root = TK ()
Fm = []
# Differentiate frames by different colors
For color in ['red', 'blue']:
# Note that the method for creating a frame is different from the method for creating other controls. The first parameter is not root.
FM. append (frame (Height = 200, width = 400, BG = color ))
# Add a label to the frame below
Label (FM [1], text = 'Hello label'). Pack ()
FM [0]. Pack ()
FM [1]. Pack ()
Root. mainloop ()
# The label is added to the following frame, rather than the top of the root default.
# Most of the methods are from GM, which will be introduced later when GM is used.
'''3. After tk8.4, a type of labelframe is added to the frame, and the title Support is added '''
From tkinter import *
Root = TK ()
For lf in ['red', 'Blue ', 'yellow']:
# You can use the text attribute to specify the title of the frame.
Labelframe (Height = 200, width = 300, text = lf). Pack ()
Root. mainloop ()
Frame in tkinter tutorial