[Tutor] Tkinter class question
Peter Otten
__peter__ at web.de
Sat Apr 8 06:16:05 EDT 2017
Phil wrote:
> On Sat, 08 Apr 2017 09:12:17 +0200
> Peter Otten <__peter__ at web.de> wrote:
>
> Thank you yet again Peter.
>
> I realised what the answer is after taking a break for a couple of hours,
> however, I didn't know about:
>
>> ...
>> self.check_button = Button(
>> master,
>> text="Check",
>> command=self.check_2_2 # note there's no () -- the bound
>> method # is not invoked
>> )
>> ...
>>
>
> My working method uses the ()
This is unlikely unless you have found out about factory methods (functions
that return functions).
> but I will remove them and see what
> difference it makes.
Make sure you understand the difference between calling a function and
passing around a function as a value.
def f(): return 42
a = f
b = f()
You have understood the difference if you can predict the outcome of
all four lines below:
print(a)
print(b)
print(a())
print(b())
Once you think you know the answer try it in the interactive interpreter.
More information about the Tutor
mailing list