Tkinter: button (beginner question)

Roman Suzi rnd at onego.ru
Thu Oct 4 09:58:28 EDT 2001


On Wed, 3 Oct 2001, Uwe Mayer wrote:

> hi,
> 
> the following was supposed to display a Tkinter button with an image	on 
> it (i.e for a toolbar):
> 
> --
> from Tkinter import *
> root = Tk()
- > b = Button(root,image='test.bmp')
> b.pack()

Try:

img = PhotoImage("test.bmp")
b = Button(root, image=img)

or:

b = Button(root, bitmap="@x1.xbm")

if you prefer xbm.


(I am not sure bmp works)

> where 'test.bmp' is an image in the same folder python interactive shell 
> was started.
> however, pyhton aborts on the 3rd line with:
> 
> --
> >>> b = Button(root,image='x1.xbm')
> Traceback (most recent call last):
>   File "<stdin>", line 1, in ?
>   File "C:\Python21\lib\lib-tk\Tkinter.py", line 1817, in __init__
>     Widget.__init__(self, master, 'button', cnf, kw)
>   File "C:\Python21\lib\lib-tk\Tkinter.py", line 1756, in __init__
>     self.tk.call(
> TclError: image "x1.xbm" doesn't exist
> --
> 
> has anyone an idea what is going wrong here?
> for the reference: i am running python 2.1.1 on windows 2k.
> 
> i read the Tkinter manual examples and i don't quite know why all 
> Button, Canvas, etc. are put into a Frame widget rather than letting 
> them stay in the "root = Tk()" widget, or Toplevel widget (-> Dialog 
> window example). Where's the difference?
> 
> Thanx in advance for comments.
> Yours
> Uwe
> 

Sincerely yours, Roman A.Suzi
-- 
 - Petrozavodsk - Karelia - Russia - mailto:rnd at onego.ru -
 





More information about the Python-list mailing list