473,397 Members | 1,969 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,397 software developers and data experts.

ImageTk.Photoimage not displayed

hi
i am trying to display an image on a canvas in a gui made with Tkinter
widgets
class PhotoDisplay:
def __init__(self,parent):
self.mainframe = Frame(parent,background="grey")
.....
#added a subframe to hold canvas and button
....
self.canvFrame=Frame(self.mainframe,...)
....
self.mycanvas=Canvas(self.canvFrame,...)
...

def okbuttonClick(self):
self.mycanvas.delete(ALL)
myimagename=...#get an imagefilename from somewhere..
self.showSelectedImage(myimagename)

def showSelectedImage(self,imageName):
myimg=ImageTk.PhotoImage(file=imageName)
imgtag=self.mycanvas.create_image(70,100,image=myi mg)
self.mycanvas.update_idletasks()
when i click the button ,the image is displayed for a fraction of a
second on the canvas and disappears.I couldn't figure out why this is
happening.I am quite new to Tkinter and still going thru Fredrik
Lundh's intro to tkinter..can someone tell me if i am doing sthing
wrong here?
thanks in advance
harry
Aug 28 '08 #1
1 3112
On Thu, Aug 28, 2008 at 4:07 PM, harryos <os**********@gmail.comwrote:
hi
i am trying to display an image on a canvas in a gui made with Tkinter
widgets
class PhotoDisplay:
def __init__(self,parent):
self.mainframe = Frame(parent,background="grey")
.....
#added a subframe to hold canvas and button
....
self.canvFrame=Frame(self.mainframe,...)
....
self.mycanvas=Canvas(self.canvFrame,...)
...

def okbuttonClick(self):
self.mycanvas.delete(ALL)
myimagename=...#get an imagefilename from somewhere..
self.showSelectedImage(myimagename)

def showSelectedImage(self,imageName):
myimg=ImageTk.PhotoImage(file=imageName)
imgtag=self.mycanvas.create_image(70,100,image=myi mg)
self.mycanvas.update_idletasks()
when i click the button ,the image is displayed for a fraction of a
second on the canvas and disappears.I couldn't figure out why this is
happening.I am quite new to Tkinter and still going thru Fredrik
Lundh's intro to tkinter..can someone tell me if i am doing sthing
wrong here?
You have to keep a reference to these images you are creating,
otherwise as soon as those methods finishes they are gone.
thanks in advance
harry
--
http://mail.python.org/mailman/listinfo/python-list


--
-- Guilherme H. Polo Goncalves
Aug 28 '08 #2

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

Similar topics

1
by: Gregor Lingl | last post by:
Hi all, The Tkinter PhotoImage Widget can be set to "transparent" with the method blank(). Moreover the color of single pixels or definite regions can be set with method put. I'd like to...
1
by: Harlin Seritt | last post by:
Why is that I can only get the PhotoImage class to show up when I write a straight procedural script (no object orientation) but not when I try to use object-orientation? These two scripts in...
0
by: Adonis | last post by:
I have two classes one class inherits dict(), this class just takes in a path argument much like glob.glob() and loads the image using PhotoImage into itself, no biggie works fine. The other class...
5
by: Bob | last post by:
I am displaying a form with a datagrid populated from a select of database records which now exceed 12,000 when I select them all. The form displays just fine with all 12,000+ entries but when I...
1
by: Bob | last post by:
I am displaying a form with a datagrid populated from a select of database records which now exceed 12,000 when I select them all. The form displays just fine with all 12,000+ entries but when I...
2
by: jburkle | last post by:
The following is the onclick method called when the "Renew" button is clicked by the user in my Windows application: ..... Private Sub cmdRenew_Click(ByVal eventSender As System.Object, ByVal...
2
by: vm | last post by:
please help! I can't find anything wrong (except the result ofc ;-) This: picfile = 'logo.gif'
0
by: shadowsithe | last post by:
I can't seem to find a way to convert an Image.Tk PhotoImage to a PIL Image so that I can use the save function.
2
by: =?iso-8859-1?q?C=E9dric_Lucantis?= | last post by:
Hi, I can only load gif images with Tkinter.PhotoImage and none with BitmapImage. I tried png, jpg, bmp and xpm and always got this errors : Traceback (most recent call last): File...
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: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...
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...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.