473,669 Members | 2,452 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.GI F")
Background = MainFrame.creat e_image(0, 0, image=Backgroun dFile)

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.GI F")
Tank1 = self.MainFrame. create_image(0, 0, image=Backgroun dFile)

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

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

Jay

Apr 8 '06 #1
6 5957
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.GI F")
Tank1 = self.MainFrame. create_image(0, 0, image=Backgroun dFile)

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.GI F")
Background = self.MainFrame. create_image(0, 0,
image=Backgroun dFile)
Background.imag e = 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.GI F")
Background = self.MainFrame. create_image(0, 0,
image=Backgroun dFile)
Background.imag e = 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.GI F")
Background = self.MainFrame. create_image(0, 0, image=Backgroun dFile)
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
5969
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 filling the remainder of the window. Mind you, this is a contrived test application to help me understand Tkinter and Python, not an actual application yet. I've trivially subclassed Tkinter.Canvas into ColorCanvas, added a bunch of ColorCanvases...
3
7022
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 import * class App:
1
2967
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 scroll-bars work as advertised. That's great. However, if you click the Left Mouse button, it calls code which expands the width of the canvas by 100 pixels. The area being viewed expands correspondingly..... BUT I DON'T WANT IT TO!!
0
3578
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 accordingly. However, what I really want to happen is that the area of the canvas that the scrollbars show (the Scrollregion) should expand as the window grows. It doesn't currently do this. although, if the window shrinks smaller than the...
1
3595
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 I am hoping someone knows what I am doing wrong: 1) Pressing the Settings.. Button multiple times, brings up many instances of the Settings Panel. I just want it to bring up one. Is there an easy way to do that?
3
3605
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 yesterday), so I am sure I am overlooking something simple. The basic idea is that my application will consist of a series of modal dialogs, that are chained together in "wizard" fashion. There will be some processing in between dialogs, but for the most...
1
5229
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 last): File "C:\Documents and Settings\yvesd\Bureau\protowin.py", line 36, in ? b1 = Tkinter.Button (win1)
8
3280
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 my pc. But, it is not getting installed and is failing by throwing the below errors. Should i need to configure / install any specific files for resolving this issue ?
3
2979
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 guess my question is two-fold. 1) How do I get rid of that window? 2) Any comments in general? I am just learning python (and coding with classes), so I'm sure there are things I should pound into my head before I learn bad habits. Here's the...
3
3911
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 this I mean that the format would be something like this: You have Page1 : This has 2-3 buttons on it. Clicking on each button opens up a new window respectively having
0
8465
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
8383
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
8658
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...
1
6210
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
4206
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
4386
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2797
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
2
2032
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1788
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.