ttk.Button returns None

前端 未结 1 527
谎友^
谎友^ 2020-12-04 02:54

I am trying to use the invoke method of a ttk.Button, as shown at TkDocs (look at \"The Command Callback\"), but I keep getting this error:

A

相关标签:
1条回答
  • 2020-12-04 03:19

    No, you're entirely wrong: your code does not show that ttk.Button returns None -- it shows that the grid method on the button object returns None! Don't you see that you're calling .grid on whatever it is that ttk.Button returns (the button object), and it's the result of that grid call that you're assigning to "button"?!

    So do it right instead...:

    button = ttk.Button(root, text="Test")
    button.grid(row=0, column=0)
    

    now you can print button and of course the results will be very different!-)

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