473,625 Members | 2,853 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Question Regarding PIL and PhotoImage classes

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()
im = Image.open('ima ge.gif')
photo = ImageTk.PhotoIm age(im)

label = Label(image=pho to)
label.pack()
root.mainloop()

---Object-Oriented---

from Tkinter import *
import Image, ImageTk

class App:

def __init__(self, master):
im = Image.open('del lserver.gif')
photo = ImageTk.PhotoIm age(im)

label = Label(master, image=photo)
label.pack()
if __name__ == '__main__':
root = Tk()
app = App(root)
root.mainloop()

---END of CODE---

Thanks,

Harlin Seritt

Jul 19 '05 #1
1 1294
Harlin Seritt wrote:
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?


in the second example, the "photo" variable is garbage-collected when the
method returns.

see the note on this page for more info:

http://effbot.org/zone/tkinter-photoimage.htm

</F>

Jul 19 '05 #2

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

Similar topics

0
4872
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 (PyGame, wxPython, PyQt, etc. are not really suitable for this program, for a number of reasons, and I have zero interest in discussing why right now). Since the Tkinter.PhotoImage.copy() method doesn't allow a region parameter, I have to save...
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
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...
6
2111
by: rodchar | last post by:
Hey all, I'm trying to understand Master/Detail concepts in VB.NET. If I do a data adapter fill for both customer and orders from Northwind where should that dataset live? What client is responsible for instantiating the orders class? Would it be the ui layer or the master class in the business layer? thanks,
10
3436
by: jojobar | last post by:
Hello, I am trying to use vs.net 2005 to migrate a project originally in vs.net 2003. I started with creation of a "web site", and then created folders for each component of the site. I read somewhere that each folder under the "web site" is compiled in separate assembly. I however, did not find that the "web site" creation in vs.net 2005 created any AssemblyInfo.cs file.
2
6740
by: vm | last post by:
please help! I can't find anything wrong (except the result ofc ;-) This: picfile = 'logo.gif'
6
3542
by: Nebulism | last post by:
I have been attempting to utilize a draw command script that loads a canvas, and through certain mouse events, draws rectangles. The original code is from http://www.java2s.com/Code/Python/Event/Usemousetodrawashapeoncanvas.htm . The code itself is: from Tkinter import * trace = 0 class CanvasEventsDemo: def __init__(self, parent=None): canvas = Canvas(width=300, height=300, bg='beige') canvas.pack()
3
4956
by: Nebulism | last post by:
Hi everyone, I am working on a module for my GUI that shows one image with an index value below and would use a scrollbar to control which of the images are displayed. The images are stored in a successive folder in the format Pic#, i,e. Pic1, Pic2 etc. What I want to do is make a slider that is attached to a label which would output the slide number that is being looked at. I would use that number then to return the image of the slide...
1
1809
by: jimgardener | last post by:
hi I am using Python 2.5.1. In my code i want to use self.myimage=PhotoImage (file=self.myfile) so i can create the image in a canvas self.mycanv.create_image(70,100,image=self.myimg) it works when i add, from ImageTk import PhotoImage
0
8253
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8692
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...
0
8635
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8354
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
8497
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
5570
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4089
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...
0
4192
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2621
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

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.