Frame in tkinter tutorial

Source: Internet
Author: User
Tags tkinter tutorial

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

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.