Thread: Add Image

    #1
  1. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2003
    Location
    Somewhere over the Rainbow
    Posts
    128
    Rep Power
    11

    Add Image


    Hi, I would like some help to add an image to my button, this is my toolbar code:

    Code:
    Self.toolbar = Frame(self.window)
            
            self.new = Button(self.toolbar, text="New", width=6, command=self.new, relief=RIDGE)
            self.new.pack(side=LEFT, padx=2, pady=2)
    Thanks a lot.
  2. #2
  3. Hello World :)
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2003
    Location
    Hull, UK
    Posts
    2,537
    Rep Power
    69
    Mmmmm.. does this work for you because i don't see how it could

    Self.toolbar should be self.toolbar (thats the main problem) and the wierd indentation is gonna make Python puke if you feed this too it

    Mark.
    programming language development: www.netytan.com Hula

  4. #3
  5. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2003
    Location
    Somewhere over the Rainbow
    Posts
    128
    Rep Power
    11
    Thanks, I change it for self.toolbar = Frame(self.window).

    but how can I add a simple icon to the button, Thanks again
  6. #4
  7. Banned ;)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Nov 2001
    Location
    Woodland Hills, Los Angeles County, California, USA
    Posts
    9,616
    Rep Power
    4247
    Code:
    from Tkinter import *
    
    root = Tk()
    
    myimage = PhotoImage(file='myimage.gif')
    
    button = Button(root, image=myimage)
    button.pack()
    
    root.mainloop()
    Up the Irons
    What Would Jimi Do? Smash amps. Burn guitar. Take the groupies home.
    "Death Before Dishonour, my Friends!!" - Bruce D ickinson, Iron Maiden Aug 20, 2005 @ OzzFest
    Down with Sharon Osbourne

    "I wouldn't hire a butcher to fix my car. I also wouldn't hire a marketing firm to build my website." - Nilpo
  8. #5
  9. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2003
    Location
    Somewhere over the Rainbow
    Posts
    128
    Rep Power
    11
    Thanks, I added the image in the toolbar, but now I have a problem, Im making a Text editor when I add self.root.mainloop() the text editor disappear, and when I remove it, the text editor appears and the image disappear. What could be the problem?



    Code:
    	self.toolbar = Frame(self.window)
    	image=PhotoImage(file='/home/neo/Images/new.gif') 
            
    	self.new = Button(self.toolbar,image=image,width=40, command=self.new, relief=RIDGE)
            self.new.pack(side=LEFT, padx=2, pady=2)  
    
          
            self.toolbar.pack(side=TOP, fill=X)
    	self.window.mainloop()
  10. #6
  11. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2003
    Location
    Somewhere over the Rainbow
    Posts
    128
    Rep Power
    11
    Thanks to all, I fixed, now is working fine.

IMN logo majestic logo threadwatch logo seochat tools logo