473,382 Members | 1,329 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

Tkinter Images

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!

Nov 23 '05 #1
2 3712
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?

Nov 23 '05 #2
"Tuvas" wrote:
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>

Nov 23 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Mark 'Kamikaze' Hughes | last post by:
In the new Python game I'm developing, I need to crop out individual tiles from larger tilesets, and maintain transparency. Unfortunately, I've run into major deficiencies in both Tkinter and PIL...
2
by: Michael Zhang | last post by:
My project uses Python-2.3.4 + Tkinter + PIL-1.1.4 to retrieve images from server and display those images. I created a thread (also a separate toplevel window) for displaying images and another...
4
by: Ron Provost | last post by:
Hello, I'm using python 2.4.2 on Win XP Pro. I'm trying to understand a behavior I'm seeing in some Tkinter code I have. I've reduced my question to a small piece of code: #####BEGIN CODE...
0
by: erkidevries | last post by:
Problem compiling Tkinter program with bmp images (using py2exe) I have a Tkinter gui program that uses bmp as backgrounds. The program itself works when I run from the source. I placed the...
2
by: Fuzzyman | last post by:
Hello all, I have some Tkinter buttons that display images. I would like to change these to 'active' images when the mouse is over the button. I see that the button widget can take an...
3
by: aldonnelley | last post by:
Hi all. Just having a weird problem with tkinter. I'm trying to make a gui that shows results from an image search, with a "forward" and "back" button so the user can compare results from...
5
by: exhuma.twn | last post by:
As many might know, windows allows to copy an image into the clipboard by pressing the "Print Screen" button on the keyboard. Is it possible to paste such an image from the clipboard into a "Text"...
2
by: defn noob | last post by:
from Tkinter import * import os master = Tk() w = Canvas(master, width=800, height=600) print os.path.exists('C:/me/saftarn/desktop/images/blob4.jpg') im = PhotoImage(file =...
2
by: Pedro | last post by:
Hi I'm trying to build a small application that can display some images in a toplevel window. I have this code: def Results(master): from Tkinter import Toplevel, Button, Label from PIL...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.