Python – GUI Programming

 

Python supports a variety of GUI frameworks or toolkits, from Tkinter which is traditionally bundled with Python, to a number of cross-platform solutions, such as PyQT or wxPython, that you can install as third-party libraries.

Python provides various options for developing graphical user interfaces (GUIs). Most important are listed below.

  • Tkinter − Tkinter is the Python interface to the Tk GUI toolkit shipped with Python. We would look this option in this chapter.

  • wxPython − This is an open-source Python interface for wxWindows http://wxpython.org.

  • JPython − JPython is a Python port for Java which gives Python scripts seamless access to Java class libraries on the local machine http://www.jython.org.

There are many other interfaces available, which you can find them on the net.

 

Example

#!/usr/bin/python

import Tkinter
top = Tkinter.Tk()
# Code to add widgets will go here...
top.mainloop()

Let us study these widgets in detail −

Let us study these widgets in detail −

Standard attributes

Let us take a look at how some of their common attributes.such as sizes, colors and fonts are specified.

Let us study them briefly −

Geometry Management

ll Tkinter widgets have access to specific geometry management methods, which have the purpose of organizing widgets throughout the parent widget area. Tkinter exposes the following geometry manager classes: pack, grid, and place.

  • The pack() Method − This geometry manager organizes widgets in blocks before placing them in the parent widget.

  • The grid() Method − This geometry manager organizes widgets in a table-like structure in the parent widget.

  • The place() Method − This geometry manager organizes widgets by placing them in a specific position in the parent widget.

Let us study the geometry management methods briefly −

Leave a Comment

Your email address will not be published. Required fields are marked *