'NoneType' object has no attribute 'config'

前端 未结 1 1934
北荒
北荒 2020-12-17 22:47

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()

相关标签:
1条回答
  • 2020-12-17 23:28
    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")
    pButton.grid(row=1)
    pButton.config(image=PlayUp)
    

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

    0 讨论(0)
提交回复
热议问题