我是一个Python(3.1.2)/emacs(23.2)新手,正在使用在这里找到的pythonware教程自学tkinter。相关代码已粘贴在问题下面。
问题:当我点击Hello按钮(应该调用say_hi函数)时,为什么劣质的python shell(即我用C-c C-c启动的那个)要等到我单击Quit按钮或关闭根部组件之前才执行say_hi打印函数?在IDLE中尝试相同操作时,每次单击Hello按钮都会立即在IDLE python shell中打印,甚至在我单击Quit或关闭根组件之前就会打印。
是否有一些emacs运行Python shell(与IDLE相比)的怪癖导致了这种“滞后”行为?当我通过Project Euler问题进行工作时,我已经注意到类似的emacs滞后与IDLE,但这是我迄今所见过的最清晰的例子。
FYI:我使用python.el并拥有一个相对干净的init.el...
(setq python-python-command "d:/bin/python31/python")
是我init.el中唯一的一行。
谢谢,
Mike
=== 开始代码 ===
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()
print('abc', file=sys.stderr)
,可能是缓冲问题(输出到控制台可能是行缓冲,但输出到管道/文件可能有固定缓冲区)。 - jfs