The nub of the matter is, what am I doing wrong in the following code snippet?
from tkinter import *
from tkinter.ttk import *
root = Tk()
myButton = Button(root)
myImage = PhotoImage(myButton, file='myPicture.gif')
myButton.image = myImage
myButton.configure(image=myImage)
root.mainloop()
The error message I get from idle3 is as follows:
>>>
Traceback (most recent call last):
File "/home/bob/Documents/Python/tkImageTest.py", line 9, in <module>
myButton.configure(image=myImage)
File "/usr/lib/python3.2/tkinter/__init__.py", line 1196, in configure
return self._configure('configure', cnf, kw)
File "/usr/lib/python3.2/tkinter/__init__.py", line 1187, in _configure
self.tk.call(_flatten((self._w, cmd)) + self._options(cnf))
TypeError: __str__ returned non-string (type Button)
>>>
This error message has me stumped, I simply don't understand what it is trying to say. Any ideas?
I would also appreciate suggestions for changes...
myButtonargument passed toPhotoImage(). I don't believe thatPhotoImage()takes a reference to a widget object, so this may be causing the error. Try that line without it, such asmyImage = PhotoImage(file='myPicture.gif')PhotoImageneeds an explicit reference to the root window. After some more fiddling I found the reference to either the root or the button itself can be provided by another configuration option on thePhotoImageconstructor like this,PhotoImage(master=myButton, file='myFile.gif'), but the way I have written it, it looks to Tkinter like a name, which is supposed to be a string, ofc.