我是一个python(3.1.2)/emacs(23.2)新手,正在使用pythonware教程自学tkinter
here
. 相关代码粘贴在问题下方。
问题:当我单击hello按钮(应该称为say-hi函数)时,为什么下面的python shell(即我用c-c c-c启动的shell)会等待执行say-hi print函数,直到a)单击quit按钮或b)关闭根窗口小部件?当我在空闲时尝试相同的方法时,每次单击hello按钮都会在空闲的python shell中立即生成一个打印,甚至在单击quit或close root小部件之前也是如此。
Emacs运行python shell(与idle相比)的方式是否有一些奇怪之处,从而导致这种“滞后”行为?我注意到类似的Emacs滞后于空闲,因为我已经解决了ProjectEuler问题,但这是我见过的最清楚的例子。
仅供参考:我使用python.el并有一个相对干净的init.el…
(setq python python命令“d:/bin/python31/python”)
是我的init.el中唯一的一行。
谢谢,
迈克
===开始代码===
from tkinter import *
class App:
def __init__(self,master):
frame = Frame(master)
frame.pack()
self.button = Button(frame, text="QUIT", fg="red", command=frame.quit)
self.button.pack(side=LEFT)
self.hi_there = Button(frame, text="Hello", command=self.say_hi)
self.hi_there.pack(side=LEFT)
def say_hi(self):
print("hi there, everyone!")
root = Tk()
app = App(root)
root.mainloop()