Python Tkinter Programming

Source: Internet
Author: User

Python provides a variety of scenarios for developing a graphical user interface (GUI). Listed below are the most important:

    • The Tkinter:tkinter is the TK GUI toolkit, which is the Python interface included with Python. In this tutorial we will look at this option.

    • WxPython: This is an open source Python interface for Wxwindows http://wxpython.org.

    • Jpython:jpython is a python port for Java,

      This allows Python scripts to be seamlessly accessed on the local machine to the Java class Library http://www.jython.org.

There are a lot of other interfaces available that I don't have listed here. You can find them over the network.

Tkinter Programming:

Tkinter is the standard Python GUI library. The combination of Python and Tkinter provides a quick and easy way to create GUI applications. Tkinter provides a powerful object-oriented interface to TK's GUI toolkit.

It is easy to create a GUI application using Tkinter. All you need to do is to perform the following steps:

    • Import the tkinter module .

    • Create the main window of the GUI application.

    • Add one or more GUI applications of the above parts.

    • Each event response is triggered by the user entering the main event loop.

Example:
#!/usr/bin/pythonimport tkintertop = tkinter.tk () # Code to add widgets would go Here...top.mainloop ()

This creates one of the following windows:

Parts of Tkinter:

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 parts.

There are currently 15 types of tkinter components. We present these parts as well as a brief introduction in the following table:

Operator Description
Button The Button widget is used to display buttons in your application.
Canvas The Canvas widget is used-draw shapes, such as lines, ovals, polygons, and rectangles, in your application.
Checkbutton The Checkbutton widget is used to display a number of options as checkboxes. The user can select multiple options at a time.
Entry The Entry widget is used to display a single-line text field for accepting values from a user.
Frame The Frame widget is used as a container widgets to organize and other widgets.
Label The Label widget is used-provide a single-line caption for other widgets. It can also contain images.
Listbox The Listbox widget is used to provide a list of options to a user.
Menubutton The Menubutton widget is used to display menus in your application.
Menu The Menu widget is used to provide various commands to a user. These commands is contained inside Menubutton.
Message The Message widget is used to display multiline text fields for accepting values from a user.
Radiobutton The Radiobutton widget is used to display a number of options as radio buttons. The user can select only one option at a time.
Scale The scale widget is an used to provide a slider widget.
Scrollbar The Scrollbar widget is used to add scrolling capability to various widgets, such as list boxes.
Text The text widget is used to display Text in multiple lines.
TopLevel The TopLevel widget is used to provide a separate window container.
Spinbox The Spinbox widget is a variant of the Tkinter Entry widget, which can be used to select from a fixed number of V Alues.
Panedwindow A panedwindow is a container widget, which may contain any number of panes, arranged horizontally or vertically.
Labelframe A labelframe is a simple container widget. Its primary purpose are to act as a spacer or container for complex window layouts.
Tkmessagebox This module was used to display message boxes in your applications.
Standard properties:

Let's take a look at how some of their common attributes are. such as size, color and font designation.

    • Dimensions

    • Colors

    • Fonts

    • Anchors

    • Relief Styles

    • Bitmaps

    • Cursors

Geometry Management:

Tkinter parts have a specific geometry of the management method, the entire widget for the purpose of the parent control area organization. Tkinter exposes the following Geometry manager classes: Packaging, grid, position.

    • Pack () method-This geometry manager is organized before it is placed in their parent widget block part.

    • Grid () Method-This geometry manager organizes the parent parts of the widgets in the table structure.

    • Place () method -This geometry manager organization is placed in a specific location in their parent widget widget.

Python Tkinter Programming

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.