Kyle Kyle - 1 year ago 106
Python Question

'NoneType' object has no attribute 'config'

what I am trying to do here is add the image to the button I have, then based on click or hover change the image. All the examples I have followed use the .config method. For the life of me I can't figure out why it doesn't know what the button object is. What is interesting is that if I modify the Button definition line to include the image option, everything is fine. But, with that there it seems I can't modify it using .config

PlayUp = PhotoImage(file=currentdir+'\Up_image.gif')
PlayDown = PhotoImage(file=currentdir+'\Down_image.gif')
def playButton():
pButton = Button(root, text="Play", command="playButton").grid(row=1)

Answer Source
pButton = Button(root, text="Play", command="playButton").grid(row=1)

Here you are creating an object of type Button, but you are immediately calling the grid method over it, which returns None. Thus, pButton gets assigned None, and that's why the next row fails.

You should do instead:

pButton = Button(root, text="Play", command="playButton")

i.e. first you create the button and assign it to pButton, then you do stuff over it.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download