[Tkinter-discuss] 回复: 回复: why tkinter do not quit?

Bob van der Poel bob at mellowood.ca
Wed Aug 10 18:13:29 CEST 2011


2011/8/9 守株待兔 <1248283536 at qq.com>:
> i am sitll confused,please  see the following
>>>> def  abc():
> ...   print  "i am abc"
> ...   return  "i am not abc"
> ...
>>>> abc
> <function abc at 0xb780d17c>
>>>> abc()
> i am abc
> 'i am not abc'
>>>>
> code1
>
> import Tkinter
> def  abc():
>   print  "i am abc"
>   return  "i am not abc"
> top=Tkinter.Tk()
> button=Tkinter.Button(top,text = 'Hello Button',command =abc)
> button.pack()
> top.mainloop()
>
> when you click button ,the output is :
> i am abc
> my question is :where is the "i am not abc"??

When a function is called as a callback there is no return value. If
you want a value from a callback you need to have the callback save it
"somewhere".

> code2
> import Tkinter
> def  abc():
>   print  "i am abc"
>   return  "i am not abc"
> top=Tkinter.Tk()
> button=Tkinter.Button(top,text = 'Hello Button',command =abc())
> button.pack()
> top.mainloop()
>
> when code2 run ,there is output  "i am abc",(where is "i am not abc")?
>
> when you click button ,there is no reaction, why?
>
>
>
>
> ------------------ 原始邮件 ------------------
> 发件人: "Igor Novikov"<igor.e.novikov at gmail.com>;
> 发送时间: 2011年8月9日(星期二) 晚上10:20
> 收件人: "守株待兔"<1248283536 at qq.com>;
> 抄送: "Tkinter-discuss"<Tkinter-discuss at python.org>;
> 主题: Re: 回复: [Tkinter-discuss] why tkinter do not quit?
>
>
> 2011/8/9 守株待兔 <1248283536 at qq.com>
>>
>>
>> what is the difference  between  quit and quit() ??
>
> quit is a reference to callable but quit() is a method call.
> The code command = top.quit just passes a callable reference,
> but command = top.quit() passes result of top.quit() execution.
> Possibly exception could be raised in last case.
>
> --
> Regards,
>
> Igor Novikov
> sK1 Project
> http://sk1project.org
>
>
>
> _______________________________________________
> Tkinter-discuss mailing list
> Tkinter-discuss at python.org
> http://mail.python.org/mailman/listinfo/tkinter-discuss
>
>



-- 
**** Listen to my CD at http://www.mellowood.ca/music/cedars ****
Bob van der Poel ** Wynndel, British Columbia, CANADA **
EMAIL: bob at mellowood.ca
WWW:   http://www.mellowood.ca


More information about the Tkinter-discuss mailing list