Welcome, guest | Sign In | My Account | Store | Cart

The simple Jython function below accepts a url string for an image and displays it in a Swing window.

Python, 10 lines
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
from pawt import swing
from java import net

def view(url):
	frame = swing.JFrame("Image: " + url, visible=1)
	frame.getContentPane().add(swing.JLabel(swing.ImageIcon(net.URL(url))))
	frame.setSize(400,250)
	frame.show()
	
view("http://www.python.org/pics/pythonHi.gif")

Swing's JLabel and ImageIcon can be combined in Jython to make a simple image viewer. This combination is a not so obvious but easy way to display a web-based image. You can also use the "file:///" protocol to display images on your file system.

Created by Joel Lawhead on Mon, 17 Nov 2003 (PSF)
Python recipes (4591)
Joel Lawhead's recipes (3)

Required Modules

Other Information and Tasks