How to Create Graphical Interfaces In Python Programming Language?

Graphical Interfaces Windowing applications are written in JPython using the same set of options that you have available for Java applications. Currently, the two names that you will hear most for this kind of implementation are awtand swing.

AWT stands for Abstract Windowing Toolkit, which is the official name for the Java GUI. Note that the syntax is very similar to Tkinter, thus it will not be a problem for you to understand and use it.
import java

frame=java.awt.Frame(“Ni!”,visible = 1)
labeltop=java.awt.Label(“Hello Python World!”)
frame.add(labeltop)
frame.pack()

JPython also contains a package called pawt(stands for Python AWT), which wrappes the access to awt, providing some additional functionality.

The successor of Java’s windowing toolkit is provided as part of the Java Foundation Classes. This set of classes extends the original AWT by adding a comprehensive set of graphical user interface class libraries, commonly known as JFC/Swing GUI Components, or simply Swing. These components are simple to read and understand, and they are written in the Java programming language, without window-system–specific code. This causes less problems when distributing JPython applications because you do not rely on the code of a specific windowing system.

At this page, you can download the latest version of the Java Foundation Classes (JFC)/Swing, whichat this moment is in release 1.1.1. After downloading it, make sure that you have the following environment variables correctly defined: JAVA_HOME, SWING_HOME, CLASSPATH, and PATH.

Next, you have the section of the autoexec.bat of my Win98 machine that handles these definitions, for your information.

set JAVA_HOME=C:\JDK1.1.8
set SWING_HOME=C:\JDK1.1.8\swing-1.1.1
set PATH=%PATH%;%JAVA_HOME%\bin
set CLASSPATH=.;%JAVA_HOME%\lib\classes.zip
set CLASSPATH=%CLASSPATH%;%SWING_HOME%;%SWING_HOME%\swing.jar;
set CLASSPATH=%CLASSPATH%;%SWING_HOME%\windows.jar

The next code shows an example that uses the Python package pawtto access the swing components.

import java
importpawt
def exit(h):
java.lang.System.exit(0)
frame=pawt.swing.JFrame(‘Ni! again!’,visible=1)
display= awt.swing.JTextField()
display.text=”Click on the button below to exit!”
frame.contentPane.add(display)
button=pawt.swing.JButton(‘Exit’,actionPerformed=exit)
frame.contentPane.add(button)
frame.pack()