Mailing List Archive

Problem exiting from a script using tkinter
Hi!

Why this does not work?!

from tkinter import *

def terminate(root):
root.quit


root=Tk()
#b=Button(root,text="QUIT",command=root.quit)
b=Button(root,text="QUIT",command=lambda: terminate(root))
b.pack()

mainloop()

Thanks
--
https://mail.python.org/mailman/listinfo/python-list
Re: Problem exiting from a script using tkinter [ In reply to ]
On Sun, Nov 22, 2020 at 9:16 AM Paulo da Silva
<p_d_a_s_i_l_v_a_ns@nonetnoaddress.pt> wrote:
>
> Hi!
>
> Why this does not work?!
>
> from tkinter import *
>
> def terminate(root):
> root.quit
>

Is root.quit a function? Simply referencing a function's name does not
call it (because functions are first-class objects - you can put a
function in a variable or pass it as a parameter etc). In order to
make it do its work, you have to call it.

ChrisA
--
https://mail.python.org/mailman/listinfo/python-list
Re: Problem exiting from a script using tkinter [ In reply to ]
Às 22:18 de 21/11/20, Chris Angelico escreveu:
> On Sun, Nov 22, 2020 at 9:16 AM Paulo da Silva
> <p_d_a_s_i_l_v_a_ns@nonetnoaddress.pt> wrote:
>>
>> Hi!
>>
>> Why this does not work?!
>>
>> from tkinter import *
>>
>> def terminate(root):
>> root.quit
>>
>
> Is root.quit a function? Simply referencing a function's name does not
> call it (because functions are first-class objects - you can put a
> function in a variable or pass it as a parameter etc). In order to
> make it do its work, you have to call it.
>

A newbie Error :-(
Sorry. I am giving my first steps in tkinter and I thought it was
another problem :-)
I just copied the "root.quit" inside the function.

Thanks Chris.

--
https://mail.python.org/mailman/listinfo/python-list
Re: Problem exiting from a script using tkinter [ In reply to ]
On Sun, Nov 22, 2020 at 9:36 AM Paulo da Silva
<p_d_a_s_i_l_v_a_ns@nonetnoaddress.pt> wrote:
>
> Às 22:18 de 21/11/20, Chris Angelico escreveu:
> > On Sun, Nov 22, 2020 at 9:16 AM Paulo da Silva
> > <p_d_a_s_i_l_v_a_ns@nonetnoaddress.pt> wrote:
> >>
> >> Hi!
> >>
> >> Why this does not work?!
> >>
> >> from tkinter import *
> >>
> >> def terminate(root):
> >> root.quit
> >>
> >
> > Is root.quit a function? Simply referencing a function's name does not
> > call it (because functions are first-class objects - you can put a
> > function in a variable or pass it as a parameter etc). In order to
> > make it do its work, you have to call it.
> >
>
> A newbie Error :-(
> Sorry. I am giving my first steps in tkinter and I thought it was
> another problem :-)
> I just copied the "root.quit" inside the function.
>

No need to feel bad about it :) Getting your head around "this is a
function, that's where the function's being called" is not easy, and
it takes experience.

Your question was very well put. You provided a short, compact example
that showcased the problem you were experiencing. That made it easy to
answer your question. Keep on asking questions like that, please -
you're helping yourself and making the mailing list a great place too
:)

ChrisA
--
https://mail.python.org/mailman/listinfo/python-list
Re: Problem exiting from a script using tkinter [ In reply to ]
Às 22:44 de 21/11/20, Chris Angelico escreveu:
> On Sun, Nov 22, 2020 at 9:36 AM Paulo da Silva
> <p_d_a_s_i_l_v_a_ns@nonetnoaddress.pt> wrote:
>>
>> Às 22:18 de 21/11/20, Chris Angelico escreveu:
>>> On Sun, Nov 22, 2020 at 9:16 AM Paulo da Silva
>>> <p_d_a_s_i_l_v_a_ns@nonetnoaddress.pt> wrote:
>>>>
>>>> Hi!
>>>>
>>>> Why this does not work?!
>>>>
>>>> from tkinter import *
>>>>
>>>> def terminate(root):
>>>> root.quit
>>>>
>>>
>>> Is root.quit a function? Simply referencing a function's name does not
>>> call it (because functions are first-class objects - you can put a
>>> function in a variable or pass it as a parameter etc). In order to
>>> make it do its work, you have to call it.
>>>
>>
>> A newbie Error :-(
>> Sorry. I am giving my first steps in tkinter and I thought it was
>> another problem :-)
>> I just copied the "root.quit" inside the function.
>>
>
> No need to feel bad about it :) Getting your head around "this is a
> function, that's where the function's being called" is not easy, and
> it takes experience.
>
> Your question was very well put. You provided a short, compact example
> that showcased the problem you were experiencing. That made it easy to
> answer your question. Keep on asking questions like that, please -
> you're helping yourself and making the mailing list a great place too
> :)

Thank you :-)

Paulo
--
https://mail.python.org/mailman/listinfo/python-list