Thread: Tk graphics

  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2004
    Rep Power

    Unhappy Tk graphics

    All I want to do is put an image on a button or label in Tkinter, I know it can be done but I'me totally confused with the dozens of different instructions,please how do I do it in 1 or 2 lines?
  2. #2
  3. Mini me.
    Devshed Novice (500 - 999 posts)

    Join Date
    Nov 2003
    Cambridge, UK
    Rep Power
    To make a button with an image is a two stage process:

    1. Create an image object in which to "hold" your image:
     imageobj = Tkinter.PhotoImage(file="Path of my gif image file")
    Tkinter supports gif transparency which is very useful for most buttons.

    2. Then configure your button to use the image opbject
    mybutton = Tkinter.Button(myframe, text = "Any old text", image = imageobj, ... plus any other confiuration stuf)
    When you use an image the height and width parameters of a button still apply but they now correspond to pixels.

    BTW Did you know you can add Tooltips to your Tkinter applications? There is a module in the Idle directory that demonstrates it - with slight modification it will integrate easily into your Tkinter application. I use it when there are graphical buttons - if the user hesitates over a button up pops the text that would have been on the button if the graphic was not there.


IMN logo majestic logo threadwatch logo seochat tools logo