0

im running this small python script (using tkinter) and im encountering unexpected behaviour.

    import Tkinter as tk

    master = tk.Tk()

    def toggleComp():
        print "toggled."

    compVar = tk.IntVar()

    check_comp = tk.Checkbutton(master, text="Specify Compostition:",variable=compVar,command=toggleComp).grid(row=3,column=0,sticky=tk.W,padx=20)

    print isinstance(check_comp,tk.Checkbutton)

the last print line returns 'False'. I'd have expected 'True' as a result..

Can anyone clarify?

thanks!

K3nn3th
  • 11
  • 4
  • 2
    Briefly: because `grid()` returns `None`. Save the object first, then grid it in a separate statement. – TigerhawkT3 Dec 09 '15 at 11:06
  • 1
    This is a duplicate question. But I really don't think that's the right question to link it to. – Steven Summers Dec 09 '15 at 11:10
  • The name of the method doesn't matter. What matters is that methods operating on objects in place return `None` by convention. – TigerhawkT3 Dec 09 '15 at 11:11
  • @TigerhawkT3: _"methods operating on objects in place return `None`"_ is not absolutely true. It depends on how the function is defined. – Bryan Oakley Dec 09 '15 at 12:19
  • @BryanOakley - Well, I did say "by convention." :) And this case follows the convention, returning `None` instead of another reference to the object. So there we have it. – TigerhawkT3 Dec 09 '15 at 12:25
  • I just realised the problem when i ran accross it in another part of my program... thanks a lot though, guys! – K3nn3th Dec 10 '15 at 09:47

0 Answers0