473,327 Members | 2,069 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,327 software developers and data experts.

Tkinter

Jay
Cold somebody please enlighten me at why code 1 works perfectly and yet
code to will not display the gif file.

code 1
-----------START---------

from Tkinter import *

root = Tk()

MainFrame = Canvas(root)
MainFrame.pack()

BackgroundFile = PhotoImage(file="Background.GIF")
Background = MainFrame.create_image(0, 0, image=BackgroundFile)

root.mainloop()

-----------END---------

code 2
-----------START---------

from Tkinter import *

class App:
def __init__(self, root):
self.MainFrame = Canvas(root)
self.MainFrame.pack(fill=BOTH, expand=1)

BackgroundFile = PhotoImage(file="Background.GIF")
Tank1 = self.MainFrame.create_image(0, 0, image=BackgroundFile)

root = Tk()
app = App(root)
root.mainloop()

-----------END---------
Thanks

Jay

Apr 8 '06 #1
6 5907
Excuse me for being slightly off-topic, but why not using wxPython
(www.wxpython.org)?

Baalbek
Apr 8 '06 #2
Maybe because Tkinter comes *with* Python? It is sometimes easier to
understand the way things work in Tkinter vs wxPython as well. Though I
will add that Manning has just published "wxPython in Action" so that
should help newbies out as well.

Robert

Apr 9 '06 #3
"Jay" <fi******@gmail.com> wrote:
Cold somebody please enlighten me at why code 1 works perfectly and yet
code to will not display the gif file. code 2
-----------START---------

from Tkinter import *

class App:
def __init__(self, root):
self.MainFrame = Canvas(root)
self.MainFrame.pack(fill=BOTH, expand=1)

BackgroundFile = PhotoImage(file="Background.GIF")
Tank1 = self.MainFrame.create_image(0, 0, image=BackgroundFile)

root = Tk()
app = App(root)
root.mainloop()

-----------END---------
Thanks


you need to keep a reference to the photo object on the Python side
of things, to keep it from being garbage collected.

see the note at the bottom of this page:

http://www.effbot.org/tkinterbook/photoimage.htm

</F>

Apr 9 '06 #4
Jay
Now I just get this error message.

AttributeError: 'int' object has no attribute 'image'

But the picture appears so I am almost their.

---START---

from Tkinter import *

class App:
def __init__(self, root):
self.MainFrame = Canvas(root)
self.MainFrame.pack(fill=BOTH, expand=1)

BackgroundFile = PhotoImage(file="Background.GIF")
Background = self.MainFrame.create_image(0, 0,
image=BackgroundFile)
Background.image = BackgroundFile # keep a reference!
root = Tk()
app = App(root)
root.mainloop()

Apr 9 '06 #5
"Jay" wrote:
Now I just get this error message.

AttributeError: 'int' object has no attribute 'image'

But the picture appears so I am almost their.

---START---

from Tkinter import *

class App:
def __init__(self, root):
self.MainFrame = Canvas(root)
self.MainFrame.pack(fill=BOTH, expand=1)

BackgroundFile = PhotoImage(file="Background.GIF")
Background = self.MainFrame.create_image(0, 0,
image=BackgroundFile)
Background.image = BackgroundFile # keep a reference!


the example on that page attaches the image to a widget instance,
not a canvas object handle (which is an integer; unlike user-defined
classes, integers don't allow you to attach arbitrary attributes to
them).

if you just want to display a single image, just attach it to self:

BackgroundFile = PhotoImage(file="Background.GIF")
Background = self.MainFrame.create_image(0, 0, image=BackgroundFile)
self.image = BackgroundFile # keep a reference!

if you want to display multiple images on the canvas, use a dictionary
or a list to hold active image references.

</F>

Apr 9 '06 #6
Jay
Brill, Thanks for the help

Apr 9 '06 #7

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

Similar topics

1
by: Josh | last post by:
Caution, newbie approaching... I'm trying to come up with a very simple Tkinter test application that consists of a window with a drop-down menu bar at the top and a grid of colored rectangles...
3
by: srijit | last post by:
Hello, Any idea - why the following code crashes on my Win 98 machine with Python 2.3? Everytime I run this code, I have to reboot my machine. I also have Win32all-157 installed. from Tkinter...
1
by: syed_saqib_ali | last post by:
Please take a look at and run the code snippet shown below. It creates a canvas with vertical & Horizontal scroll-bars. If you shrink the window to smaller than the area of the canvas, the...
0
by: syed_saqib_ali | last post by:
Below is a simple code snippet showing a Tkinter Window bearing a canvas and 2 connected scrollbars (Vertical & Horizontal). Works fine. When you shrink/resize the window the scrollbars adjust...
1
by: Michael Yanowitz | last post by:
Hello: Below I have included a stripped down version of the GUI I am working on. It contains 2 dialog boxes - one main and one settings. It has the following problems, probably all related, that...
3
by: dwelch91 | last post by:
I'm trying unsuccessfully to do something in Tk that I though would be easy. After Googling this all day, I think I need some help. I am admittedly very novice with Tk (I started with it...
1
by: yvesd | last post by:
hello i want to intercept tkinter python system events like wm_delete_window and if possible for any window, but the newest code I've produced give me an error : Traceback (most recent call...
8
by: karthikbalaguru | last post by:
Hi, One of my python program needs tkinter to be installed to run successfully. I am using Redhat 9.0 and hence tried installing by copying the tkinter-2.2.2-36.i386.rpm alone from the CD 3 to...
3
by: joshdw4 | last post by:
I hate to do this, but I've thoroughly exhausted google search. Yes, it's that pesky root window and I have tried withdraw to no avail. I'm assuming this is because of the methods I'm using. I...
3
by: J-Burns | last post by:
Hello. Im a bit new to using Tkinter and im not a real pro in programming itself... :P. Need some help here. Problem 1: How do I make something appear on 2 separate windows using Tkinter? By...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
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
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.