Tkinter Images

T

Tuvas

I've been trying to use a canvas to display different pictures on a
Tkinter interface. However, it doesn't seem to update the information.
Ei, I have something like this.

canvas=Canvas(master,blah...)
canvas.pack()

def change_pic(path):
global pic
image=Image() #I'm using PIL to use the images, but I
don't think it's depended... This code's not the important one...
canvas.create_image(1,1,image=image, anchor=NW)

change_pic("test1.jpg")

I have written a simple scipt that just displays an image, without any
problems. However, when I try to change the image dynamically, it
doesn't work. If needed I can put the real code, however, it's a bit
complicated to do so, this computer doesn't support copying from the
terminal to the web browser. Thanks for the help!
 
T

Tuvas

Update: I can put the image in, but it spits out errors, adding this to
it:

canvas.insert(pic)

BTW, I noted that my code was written incorectly The function should be
as follows:

def change_pic(path):
global pic
image=Image() #I'm using PIL to use the images, but I
don't think it's depended... This code's not the important one...
pic=canvas.create_image(1,1,image=image, anchor=NW)

Note, add the first line above and it works.

The question, how do I get it to work without the error messages?
 
F

Fredrik Lundh

Tuvas said:
Update: I can put the image in, but it spits out errors, adding this to
it:

canvas.insert(pic)

the "insert" method is used to insert text into canvas text items; the
syntax is

canvas.insert(tag, position, text)

I'm not sure what you're saying here; did you get errors when you did
this, or did this eliminate whatever errors you got when you created the
image?
BTW, I noted that my code was written incorectly The function should be
as follows:

def change_pic(path):
global pic
image=Image() #I'm using PIL to use the images, but I

is that a PIL Image object or a Tkinter Image object? if you're using PIL,
you need to use the ImageTk module to convert the PIL image to a format
suitable for Tkinter.

if you're using Tkinter images, you really want the PhotoImage class. Image
is just a base class; it doesn't really provide any behaviour.
don't think it's depended... This code's not the important one...
pic=canvas.create_image(1,1,image=image, anchor=NW)

Note, add the first line above and it works.

The question, how do I get it to work without the error messages?

can you perhaps post the error message?

</F>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,796
Messages
2,569,645
Members
45,366
Latest member
GayT017679

Latest Threads

Top