Python GUI programming (Tkinter)

Source: Internet
Author: User

Python GUI programming (Tkinter)
Python GUI programming (Tkinter)

Python provides a library for multiple graphical development interfaces. Several Common Python GUI Libraries are as follows:

  • 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. They can also be used in Windows and Macintosh systems ., later versions of Tk8.0 can implement the local window style and run well on most platforms.
  • WxPython: wxPython is an open-source software and a set of excellent GUI graphics libraries in Python. It allows Python programmers to easily create a complete GUI 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 modules that do not depend on C language in standard Python. For example, the Jython user interface uses Swing, AWT, or SWT. Jython can be dynamically or statically compiled into Java bytecode. Tkinter Programming

    Tkinter is a standard Python GUI library. Python uses Tkinter to quickly create GUI applications.

    Because Tkinter is built into the python installation package, the Tkinter library can be imported after Python is installed, and the IDLE is also compiled by Tkinter, Tkinter can still cope with the simple graphic interface.

    Create a GUI Program

    • 1. Import the Tkinter Module
    • 2. Create controls
    • 3. Specify the master of the control, that is, the master of the control.
    • 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 component

      Tkinter 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 attributes

      Standard 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 Management

      The 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;

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.