新手问题...lambda改变了什么?。。。
我有一个新手问题:在
class eraser(Frame):
def __init__(self, master = None):
Frame.__init__(self, master)
Pack.config(self)
self.press = False
pic = make_picture(pick_a_file())
h = get_height(pic)
w = get_width(pic)
PILimage = pic.get_image()
tkimage = ImageTk.PhotoImage(PILimage)
self.draw = Canvas(self, width = w, height = h, background = 'black')
self.draw.image = tkimage
self.draw.create_image(0, 0, anchor=NW, image=tkimage)
self.draw.bind("<B1-Motion>", self.mousemove)
self.draw.bind("<Button-1>",self.mouselpress)
self.draw.pack()
def mousemove(self, event, size = raw_input()):
if self.press == True:
self.draw.create_line(self.lastx, self.lasty, event.x, event.y, \
fill = 'white',width = size,capstyle =ROUND)
self.lastx = event.x
self.lasty = event.y
def mouselpress(self,event):
self.press = True
self.lastx = event.x
self.lasty = event.y
def close():
filename = tkFileDialog.asksaveasfilename()
image.save(filename,'bmp')
root.quit()
def new_window():
root=Tk()
frame=eraser(root)
root.mainloop()
如果我直接运行这个文件之后,call new_window(),那么一切正常,但是在另一个文件里面,我尝试:
eraser_com = lambda : new_window()
imagemenu.add_command(label ='Erase', command = eraser_com)
却会出现以下错误:
Traceback (most recent call last):
File "C:\<string>", line 120, in <module>
File "C:\cleardraft.py", line 41, in new_window
File "C:\cleardraft.py", line 18, in __init__
File "C:\Python25\Lib\lib-tk\Tkinter.py", line 2154, in create_image
return self._create('image', args, kw)
File "C:\Python25\Lib\lib-tk\Tkinter.py", line 2145, in _create
*(args + self._options(cnf, kw))))
TclError: image "pyimage1" doesn't exist
看起来是lambda之后出现了问题
这是怎么回事呢?~
这个问题比较急,希望高手们都能来指教一下~~~谢谢了!~~~