免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2296 | 回复: 0
打印 上一主题 下一主题

新手问题...lambda改变了什么?。。。 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2007-12-04 16:14 |只看该作者 |倒序浏览
我有一个新手问题:在
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之后出现了问题
这是怎么回事呢?~
这个问题比较急,希望高手们都能来指教一下~~~谢谢了!~~~
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP