Python GUI programming (Tkinter)
Python provides a library of multiple graphical development interfaces, several common Python GUI libraries are as follows:
The Tkinter:tkinter module ("Tk interface") is the interface of Python's standard TK GUI toolkit. TK and Tkinter can be used on most Unix platforms, and can also be applied to Windows and Macintosh systems. Subsequent versions of Tk8.0 can be implemented in a native window style and run well on most platforms.
Wxpython:wxpython is an open source software, a good set of GUI graphics libraries in the Python language, allowing Python programmers to easily create complete GUI user interfaces with full function keys.
The Jython:jython program can be seamlessly integrated with Java. In addition to some standard modules, Jython uses Java modules. Jython has almost all the modules in the standard Python that do not depend on the C language. For example, Jython's user interface will use SWING,AWT or SWT. Jython can be dynamically or statically compiled into Java bytecode.
Tkinter programming
Tkinter is the standard GUI library for Python. Python uses Tkinter to quickly create GUI applications.
Since Tkinter is built into Python's installation package, as long as Python is installed to import the Tkinter library, and Idle is also written in Tkinter, for a simple graphical interface tkinter can handle it.
Create a GUI program
1. Import Tkinter Module
2. Create a control
3. Specify the master of this control, that is, which one of the controls belongs to
4. Tell GM (geometry manager) that a control has been generated.
Instance:
#!/usr/bin/python
Import Tkinter
top = tkinter.tk ()
# Enter the message loop
Top.mainloop ()
The above code executes results such as:
Tkinter components
Tkinter provides a variety of controls, such as buttons, labels and text boxes, used in a GUI application. These controls are often referred to as controls or parts.
There are currently 15 types of tkinter components. We present these parts as well as a brief introduction in the following table:
Control
Describe
Button control; Displays the button in the program.
Canvas canvas control; display graphic elements such as lines or text
Checkbutton Multi-box control; for providing multiple selection boxes in a program
Entry input controls for displaying simple text content
A frame frame control that displays a rectangular area on the screen and is used more as a container
Label Label control; can display text and bitmaps
ListBox control; In the ListBox widget is used to display a list of strings to the user
Menubutton the menu button control, because the menu item is displayed.
Menu control; Display menu bar, drop-down menu and pop-up menu
Message control; To display multiple lines of text, similar to a label
Radiobutton radio button control; Displays a single-selected button state
Scale range control; Displays a numeric scale that is the number range for the output limit
The Scrollbar scroll bar control is used when the content exceeds the visual area, such as a list box.
Text control to display multiple lines of text
TopLevel container control; used to provide a separate dialog box, similar to frame
Spinbox input control; similar to entry, but can specify input range values
Panedwindow Panedwindow is a window layout-managed plug-in that can contain one or more child controls.
Labelframe Labelframe is a simple container control. Commonly used with complex window layouts.
Tkmessagebox is used to display your application's message box.
Standard properties
Standard properties are common properties of all controls, such as size, font, color, and so on.
Property Description
Dimension control size;
Color control colors;
Font control fonts;
Anchor Anchor Point;
Relief control style;
Bitmap bitmap;
cursor cursors;
Geometry Management
The Tkinter control has a specific geometry state management method that manages the entire control area organization, which is the Tkinter exposed Geometry Management class: Package, grid, location
Geometrical method Description
Pack () packaging;
Grid () grids;
Place () position;
The above is the "Python tutorial" python GUI programming (Tkinter) content, more relevant content please pay attention to topic.alibabacloud.com (www.php.cn)!