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

Tkinter buttons with image ?


Hi everybody,

I'm just getting into Tkinter and try to create a button that displays an image
instead of text. I do something like:
tmp = PhotoImage(file='start.gif')
buttonStart = Button(frameWb,image=tmp,command=root.quit)


The button now displays a blank (grey) area of the size of the image, but as I
said, it is blank :-(.

Any idea what I'm doing wrong ?
I'm using Python2.3

Many thanks,

Axel
Jul 18 '05 #1
2 15504
ko****@molgen.mpg.de wrote:
I'm just getting into Tkinter and try to create a button that displays an
image instead of text. I do something like:
tmp = PhotoImage(file='start.gif')
buttonStart = Button(frameWb,image=tmp,command=root.quit)


The button now displays a blank (grey) area of the size of the image, but
as I said, it is blank :-(.

Any idea what I'm doing wrong ?


Using the image in Tkinter will not keep it from being garbage-collected.
You need to keep a reference to the image, either in a global variable or
like so:

buttonStart = Button(frameWb, image=tmp, command=root.quit)
buttonStart.image = tmp

Peter

Jul 18 '05 #2
> Using the image in Tkinter will not keep it from being garbage-collected.
You need to keep a reference to the image, either in a global variable or
like so:

buttonStart = Button(frameWb, image=tmp, command=root.quit)
buttonStart.image = tmp


Ah, that's the trick.

Many thanks,

Axel
Jul 18 '05 #3

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

Similar topics

0
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...
1
by: midtoad | last post by:
I'm trying to display a GIF image in a label as the central area to a Tkinter GUI. The image does not appear, though a space is made for it. Why is this so? I notice that I can display a GIF...
2
by: Michael Zhang | last post by:
My project uses Python-2.3.4 + Tkinter + PIL-1.1.4 to retrieve images from server and display those images. I created a thread (also a separate toplevel window) for displaying images and another...
2
by: Fuzzyman | last post by:
Hello all, I have some Tkinter buttons that display images. I would like to change these to 'active' images when the mouse is over the button. I see that the button widget can take an...
8
by: Jay | last post by:
I'm having a problem using lambda to use a command with an argument for a button in Tkinter. buttons = range(5) for x in xrange(5): buttons = Button(frame, text=str(x+1), command=lambda:...
5
by: exhuma.twn | last post by:
As many might know, windows allows to copy an image into the clipboard by pressing the "Print Screen" button on the keyboard. Is it possible to paste such an image from the clipboard into a "Text"...
4
Elias Alhanatis
by: Elias Alhanatis | last post by:
Hello everybody!! I would like some help with the following problem: I have the following piece of code: from Tkinter import * root = Tk()
1
by: viv1tyagi | last post by:
Hi everyone ! ! ! I'm just a month old in the world of Python and trying to develop an application using Tkinter in which a new window pops out on a particular button press.The code for this new...
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
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
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: 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: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
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.