[Tkinter-discuss] 回复: 回复: why tkinter do not quit?
Alan Gauld
alan.gauld at btinternet.com
Fri Aug 12 01:56:39 CEST 2011
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/
More information about the Tkinter-discuss
mailing list