Tkinter-Chessboard
Eric Brunel
eric.brunel at pragmadev.com
Fri Jan 4 10:14:25 EST 2002
> I'm trying my hand a gui programming in python. And the first thing I
> tried to make is a chessboard. I acheived the desired effect by drawing
> filled rectangles, now I want to put pieces on the chessboard. The
> question is, how do I load an image onto a square ?
There are two classes for images with Tkinter: BitmapImage for monochrome
ones and PhotoImage for colour ones. Creating either of them is quite
straightforward:
img = BitmapImage(file="/path/to/image/file")
or:
img = PhotoImage(file="/path/to/image/file")
The files should be in XBM format for BitmapImage and GIF for PhotoImage
(there may be other working formats, but I don't know them).
Then, to insert the images in your Canvas (assuming you've already done for
your chessboard), just do:
theCanvas.create_image(x, y, image=img)
There are as usual many options for all these, but I leave it to you to
discover them :-). For documentation, please refer to:
http://www.pythonware.com/library/tkinter/introduction/index.htm
Hope this helps.
- eb -
More information about the Python-list
mailing list