[Tutor] Beginner needs help with tkinter and images

Alan Gauld alan.gauld at btinternet.com
Wed May 18 10:34:01 CEST 2011


"Adam Westrum" <jadesaturn at gmail.com> wrote

> I've got a basic program going right now, with 4 buttons. Forward 
> backward
> right and left. Each button goes to an image of a colored circle. 
> Problem
> i'm having is that when you click a button, the picture appears. 
> When you
> click another button, a different picture appears, but the first 
> picture
> remains.

You would need to clear the original Canvas (or unpack it).
In fact you should only need a single Canvas and draw all the
circles on that rather than creating a new Canvas per image...

> Additionally, I cant seem to import any pictures at all into 
> tkinter. I get
> a tclerror saying that there is an error in the bitmap.

Look at the PhotoImage widget. You load one of those into your
parent widget (Text or Canvas) and then change the associated
file to change the image. It does only have a limited set of image
types though so you may need to transform the images to match...

HTH,

-- 
Alan Gauld
Author of the Learn to Program web site
http://www.alan-g.me.uk/





More information about the Tutor mailing list