2013-04-05 104 views
-1

我需要添加到第二个def语句才能工作?嵌套defs不工作

def main(): 
    # the user has to choose a picture and then he is asked to 
    pic = makePicture(pickAFile()) 

    # the user is asked to select a color that he wants to remove from a picture 
    color = requestString("Which color would you like to remove?") 
    show(pic) 

    # whats wrong with this last part that doesn't make the modifications to the picture 
    def RemoveColor(pic, color): 
     r = red 
     g = green 
     b = blue 
     for px in getPixels(pic): 
      setRed(px, 0) 

     for px in getPixels(pic): 
      setGreen(px, 0) 

     for px in getPixels(pic): 
      setBlue(px, 0) 

    repaint(pic) 
+1

为了让任何人能够帮助你,你需要描述你的具体问题。这段代码引用了很多未定义的函数。 – 2013-04-05 03:34:51

+0

在一个不相关的说明中,您可能想给[PEP8](http://www.python.org/dev/peps/pep-0008/),Python的风格指南,阅读。 – 2013-04-05 03:35:22

+0

你定义了removeColor,但你永远不会调用该函数。 – furins 2013-04-05 14:31:17

回答

0

这里我拿出RemoveColor功能从main功能,我把它从内main

def RemoveColor(pic, color): 
    r = red 
    g = green 
    b = blue 
    for px in getPixels(pic): 
     setRed(px, 0) 

    for px in getPixels(pic): 
     setGreen(px, 0) 

    for px in getPixels(pic): 
     setBlue(px, 0) 

def main(): 
    # the user has to choose a picture and then he is asked to 
    pic = makePicture(pickAFile()) 

    # the user is asked to select a color that he wants to remove from a picture 
    color = requestString("Which color would you like to remove?") 
    show(pic) 

    RemoveColor(pic, color) # HERE I'M CALLING RemoveColor 
    repaint(pic) 
+0

@furins ..感谢您的帖子。我还有一个问题。为什么RemoveColor(图片,颜色)不起作用,程序会通过“for”语句,但它会将所有颜色都去掉并重新绘制成黑色。我如何才能去除只需要的颜色? – EsJe 2013-04-05 17:36:13

+0

@EsJe请让我知道你正在使用的库,我会试着回答...什么库/模块定义'getPixel'? – furins 2013-04-05 18:58:48

+0

@fusins我不明白你是什么意思的模块或库,因为我是新手编程。你认为你可以更具体一点吗? – EsJe 2013-04-05 21:29:46