473,624 Members | 2,127 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

ImageTk.Photoim age 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,p arent):
self.mainframe = Frame(parent,ba ckground="grey" )
.....
#added a subframe to hold canvas and button
....
self.canvFrame= Frame(self.main frame,...)
....
self.mycanvas=C anvas(self.canv Frame,...)
...

def okbuttonClick(s elf):
self.mycanvas.d elete(ALL)
myimagename=... #get an imagefilename from somewhere..
self.showSelect edImage(myimage name)

def showSelectedIma ge(self,imageNa me):
myimg=ImageTk.P hotoImage(file= imageName)
imgtag=self.myc anvas.create_im age(70,100,imag e=myimg)
self.mycanvas.u pdate_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 3123
On Thu, Aug 28, 2008 at 4:07 PM, harryos <os**********@g mail.comwrote:
hi
i am trying to display an image on a canvas in a gui made with Tkinter
widgets
class PhotoDisplay:
def __init__(self,p arent):
self.mainframe = Frame(parent,ba ckground="grey" )
.....
#added a subframe to hold canvas and button
....
self.canvFrame= Frame(self.main frame,...)
....
self.mycanvas=C anvas(self.canv Frame,...)
...

def okbuttonClick(s elf):
self.mycanvas.d elete(ALL)
myimagename=... #get an imagefilename from somewhere..
self.showSelect edImage(myimage name)

def showSelectedIma ge(self,imageNa me):
myimg=ImageTk.P hotoImage(file= imageName)
imgtag=self.myc anvas.create_im age(70,100,imag e=myimg)
self.mycanvas.u pdate_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
2607
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 set single pixels (or some rectangular regions) to "transparent". Can I use put to
1
1294
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 theory should produce the same results but they don't. Is there any reason why? ---Procedural--- root = Tk()
0
1284
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 inherits Frame and it implements an add(self, **kw) method passes all of its arguments to a Button. My question is that when I load the images with the first class and then use dict.get(name) as the image argument for the add method the image...
5
6000
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 leave the form to go back to the originating screen, I get a "The page cannot be displayed" screen for "Cannot find server or DNS Error" "Internet Explorer". You know the page - it starts with "The page you are looking for is currently...
1
2584
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 leave the form to go back to the originating program, I get a "The page cannot be displayed" screen for "Cannot find server or DNS error" "Internet Explorer". But when I select a lesser number of records - under 12,000 (don't think there is...
2
2932
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 eventArgs As System.EventArgs) Handles cmdRenew.Click Try If x Is Nothing Then
2
6740
by: vm | last post by:
please help! I can't find anything wrong (except the result ofc ;-) This: picfile = 'logo.gif'
0
1300
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
5510
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 "<stdin>", line 1, in ? File "/usr/lib/python2.4/lib-tk/Tkinter.py", line 3206, in __init__ Image.__init__(self, 'photo', name, cnf, master, **kw) File "/usr/lib/python2.4/lib-tk/Tkinter.py", line 3162, in __init__
0
8172
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8677
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8335
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8474
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7158
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6110
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4079
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2605
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1784
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.