Python Graphical (Tkinter)

Source: Internet
Author: User

Python provides a library of multiple graphical development interfaces, several common Python GUI libraries are as follows:

    • Tkinter: The 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.
    • Jython: The 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:

1 # !/usr/bin/python 2 # -*-coding:utf-8-*- 3 4 Import Tkinter 5 top = tkinter.tk ()6#  Enter message loop 7 top.mainloop ()

Example 2:

1 #!/usr/bin/python2 #-*-coding:utf-8-*-3 4  fromTkinterImport*#Import Tkinter Library5root = Tk ()#Create a background color for a Window object6                                 #Create a list of two7Li = ['C','python','PHP','HTML','SQL','Java']8Movie = ['CSS','JQuery','Bootstrap']9Listb = Listbox (Root)#Create two list componentsTenLISTB2 =Listbox (Root) One  forIteminchLi#The first widget inserts a data A Listb.insert (0,item) -  -  forIteminchMovie#The second widget inserts data the Listb2.insert (0,item) -  -Listb.pack ()#Place the widget in the main window - Listb2.pack () +Root.mainloop ()#Enter the message loop

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 Description
Button Button control; Displays the button in the program.
Canvas A 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
Frame A frame control that displays a rectangular area on the screen and is used as a container
Label Label control; can display text and bitmaps
Listbox A list box control; a 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 Menu controls, display menu bars, drop-down menus, and pop-up menus
Message Message control: Used to display multiple lines of text, similar to label
Radiobutton radio button control; Displays a single-selected button state
Scale A range control that displays a numeric scale that is a range of numbers for the output limit
Scrollbar A scrollbar control that is used when the content exceeds a visual area, such as a list box ...
Text Text control; for displaying multiple lines of text
TopLevel A container control that provides a separate dialog box, similar to a frame
Spinbox Input controls, 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 A message box to display your application.
Standard properties

Standard properties are common properties of all controls, such as size, font, color, and so on.

Property Describe
Dimension Control size;
Color Control color;
Font control font;
Anchor Anchor Point;
Relief control style;
Bitmap Bitmap
Cursor Cursor
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 methods Describe
Pack () Packaging
Grid () Grid
Place () Position

Python Graphical (Tkinter)

Related Article

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.