Tkinter buttons with image ?

Discussion in 'Python' started by kowald@molgen.mpg.de, Aug 15, 2004.

  1. Guest

    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
     
    , Aug 15, 2004
    #1
    1. Advertising

  2. Peter Otten Guest

    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
     
    Peter Otten, Aug 15, 2004
    #2
    1. Advertising

  3. Axel Kowald Guest

    > 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
     
    Axel Kowald, Aug 16, 2004
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Roger
    Replies:
    1
    Views:
    642
    GreggTB
    May 20, 2005
  2. =?Utf-8?B?QmVu?=

    Image Buttons/Buttons not responding

    =?Utf-8?B?QmVu?=, Jul 6, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    453
    Teemu Keiski
    Jul 6, 2005
  3. Jeremy Jones

    Datagrid Nav buttons and numeric buttons

    Jeremy Jones, Mar 21, 2007, in forum: ASP .Net
    Replies:
    1
    Views:
    629
    Masudur
    Mar 22, 2007
  4. Jonathan N. Little
    Replies:
    3
    Views:
    531
    Andy Dingley
    Apr 2, 2007
  5. Dr. Leff
    Replies:
    3
    Views:
    302
    David Mark
    Oct 15, 2007
Loading...

Share This Page