回复: 回复: why tkinter do not quit?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

回复: 回复: why tkinter do not quit?

luofeiyu
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"??

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?



 
------------------ 原始邮件 ------------------
发送时间: 2011年8月9日(星期二) 晚上10:20
收件人: "守株待兔"<[hidden email]>;
抄送: "Tkinter-discuss"<[hidden email]>;
主题: Re: 回复: [Tkinter-discuss] why tkinter do not quit?
 


2011/8/9 守株待兔 <[hidden email]>


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
[hidden email]
http://mail.python.org/mailman/listinfo/tkinter-discuss
Reply | Threaded
Open this post in threaded view
|

Re: »Ø¸´£º »Ø¸´£º why tkinter do not quit?

Kevin Walzer-5
On 8/9/11 11:14 PM, ÊØÖê´ýÍÃ wrote:
> when code2 run ,there is output  "i am abc",(where is "i am not abc")?

print "i am abc"

displays the string "i am abc" in standard output.

return "i am not abc"

is the return value of the function--it is not displayed. You'd have to
use the "print" command for that.

--
Kevin Walzer
Code by Kevin
http://www.codebykevin.com
_______________________________________________
Tkinter-discuss mailing list
[hidden email]
http://mail.python.org/mailman/listinfo/tkinter-discuss
Reply | Threaded
Open this post in threaded view
|

Re: 回复: 回复: why tkinter do not quit?

bvdp
In reply to this post by luofeiyu
2011/8/9 守株待兔 <[hidden email]>:

> 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"<[hidden email]>;
> 发送时间: 2011年8月9日(星期二) 晚上10:20
> 收件人: "守株待兔"<[hidden email]>;
> 抄送: "Tkinter-discuss"<[hidden email]>;
> 主题: Re: 回复: [Tkinter-discuss] why tkinter do not quit?
>
>
> 2011/8/9 守株待兔 <[hidden email]>
>>
>>
>> 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
> [hidden email]
> 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: [hidden email]
WWW:   http://www.mellowood.ca
_______________________________________________
Tkinter-discuss mailing list
[hidden email]
http://mail.python.org/mailman/listinfo/tkinter-discuss
Reply | Threaded
Open this post in threaded view
|

Re: 回复: 回复: why tkinter do not quit?

Alan Gauld
In reply to this post by luofeiyu
On 10/08/11 04:14, 守株待兔 wrote:

> 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'

The first line is the print statement in the function.
The second line is the return value of the function. The interpreter
always displays the value of any expression you type

Wen you run the function in the script the return value is not
displayed, and since Tkinter does not store the return value of an
action it just gets lost.

> when you click button ,the output is :
> i am abc
> my question is :where is the "i am not abc"??

Lost in the garbage inside Tkinter.

> 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?

The parentheses after abc() say to Python to execute the function.
So you have assigned the return value of your function to the button's
command. So the command stores 'i am not abc' - a string.
But the button cannot execute the string so when you click it nothing
happens.

HTH,
--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/



_______________________________________________
Tkinter-discuss mailing list
[hidden email]
http://mail.python.org/mailman/listinfo/tkinter-discuss