4. Tell the GM (geometry manager) that a control is generated.Instance:
#! /Usr/bin/python #-*-coding: UTF-8-*-import Tkintertop = Tkinter. Tk () # enter the message loop top. mainloop ()
The preceding code execution result is as follows:
Instance 2:
#! /Usr/bin/python #-*-coding: UTF-8-*-from Tkinter import * # import Tkinter library root = Tk () # create the background color of the window object # create two lists: li = ['C', 'python', 'php', 'html', 'SQL ', 'java'] movie = ['css ', 'jquery', 'bootstrap '] listb = Listbox (root) # create two list components listb2 = Listbox (root) for item in li: # The first widget inserts the data listb. insert (0, item) for item in movie: # The second widget inserts the data listb2.insert (0, item) listb. pack () # Place the widget in the main window listb2.pack () root. mainloop () # enter the message loop
The preceding code execution result is as follows:
Tkinter componentTkinter provides various controls, such as buttons, labels, and text boxes, used in a GUI application. These controls are usually called controls or components.
Currently, there are 15 Tkinter components. We propose these components and a brief introduction in the following table:
Widget |
Description |
Button |
Button control; display the button in the program. |
Canvas |
Canvas control; displays graphical elements such as lines or text |
Checkbutton |
Multi-choice box control; used to provide a multi-choice box in the program |
Entry |
Input control; used to display simple text content |
Frame |
Frame control. A rectangle area is displayed on the screen and is used as a container. |
Label |
Label control; displays text and bitmap |
Listbox |
The Listbox widget is used to display a string list to users. |
Menubutton |
Menu button control, because the menu item is displayed. |
Menu |
Menu Control; display menu bar, drop-down menu, and pop-up menu |
Message |
Message control, used to display multiple lines of text, similar to label |
Radiobutton |
Single-choice button control; displays the status of a Single-choice button |
Scale |
Range control. A numeric scale is displayed, which is a numerical range within the output range. |
Scrollbar |
Scroll bar control, used when the content exceeds the visible area, such as the list box .. |
Text |
Text control; used to display multi-line text |
Toplevel |
Container control. It is used to provide a separate dialog box, which is similar to Frame. |
Spinbox |
The input control is similar to the Entry, but the input range value can be specified. |
PanedWindow |
PanedWindow is a window layout management plug-in that can contain one or more child controls. |
LabelFrame |
Labelframe is a simple container control. Common and complex window la S. |
TkMessageBox |
Display the message box of your application. |
Standard attributesStandard attributes are the common attributes of all controls, such as the size, Font, and color.
Attribute |
Description |
Dimension |
Widget size; |
Color |
Control color; |
Font |
Control font; |
Anchor |
Anchor; |
Relief |
Control style; |
Bitmap |
Bitmap; |
Cursor |
Cursor; |
Geometric ManagementThe Tkinter control has a specific geometric state management method to manage the organization of the entire control area. Here is the geometric management class exposed by Tkinter: Package, grid, and location.
Geometric Method |
Description |
Pack () |
Packaging; |
Grid () |
Grid; |
Place () |
Location; |