def randombackgroundcolor(menu): back = (random.randint(0,255),random.randint(0,255),random.randint(0,255)) ptg.Menu.__init__(menu,(800,600),back,menu.header,menu.buttons) menu.widgetlist += [ptgw.wButton("randomize button",0,"Randomize Color",(200,200),True,menu.image, func = randombackgroundcolor)] menu.widgetlist += [ptgw.wButton("reset button",0,"Reset Color",(200,300),True,menu.image, func = resetbackgroundcolor)]
def __init__(self): self.header = ['Screen 1'] self.buttons = [['Screen 2',lambda:2],['Quit',close]] ptg.Menu.__init__(self,(800,600),(150,69,69),self.header,self.buttons) self.widgetlist += [ptgw.wButton("randomize button",0,"Randomize Color",(200,200),True,self.image, func = randombackgroundcolor)] self.widgetlist += [ptgw.wButton("reset button",0,"Reset Color",(200,300),True,self.image, func = resetbackgroundcolor)] for i in self.widgetlist: i.status = 0
def resetbackgroundcolor(menu): # Re-run the menu's __init__function with the original background ptg.Menu.__init__(menu, (800, 600), (150, 69, 69), menu.header, menu.buttons) # Re-add the widgets to the menu. menu.widgetlist += [ptgw.wButton("randomize button", 0, "Randomize Color", (200, 200), True, menu.image, func=randombackgroundcolor)] menu.widgetlist += [ptgw.wButton("reset button", 0, "Reset Color", (200, 300), True, menu.image, func=resetbackgroundcolor)] menu.widgetlist += [ptgw.Checkbox("Box 1", (500, 200), (20, 20), True, menu.image)]
def __init__(self): self.header = ['Screen 1'] self.buttons = [['Screen 2', lambda:2], ['Quit', close]] ptg.Menu.__init__(self, (800, 600), (150, 69, 69), self.header, self.buttons) # Set up the widgets for the screen self.widgetlist += [ptgw.wButton("randomize button", 0, "Randomize Color", (200, 200), True, self.image, func=randombackgroundcolor)] self.widgetlist += [ptgw.wButton("reset button", 0, "Reset Color", (200, 300), True, self.image, func=resetbackgroundcolor)] self.widgetlist += [ptgw.Checkbox("Box 1", (500, 200), (20, 20), True, self.image)]
def randombackgroundcolor(menu): # Create a random rgb value. back = (random.randint(0, 255), random.randint(0, 255), random.randint(0, 255)) # Re-run the menu's __init__ function with the new background # color. ptg.Menu.__init__(menu, (800, 600), back, menu.header, menu.buttons) # Re-add the widgets to the menu. menu.widgetlist += [ptgw.wButton("randomize button", 0, "Randomize Color", (200, 200), True, menu.image, func=randombackgroundcolor)] menu.widgetlist += [ptgw.wButton("reset button", 0, "Reset Color", (200, 300), True, menu.image, func=resetbackgroundcolor)] menu.widgetlist += [ptgw.Checkbox("Box 1", (500, 200), (20, 20), True, menu.image)]
def resetbackgroundcolor(menu): ptg.Menu.__init__(menu,(800,600),(150,69,69),menu.header,menu.buttons) menu.widgetlist += [ptgw.wButton("randomize button",0,"Randomize Color",(200,200),True,menu.image, func = randombackgroundcolor)] menu.widgetlist += [ptgw.wButton("reset button",0,"Reset Color",(200,300),True,menu.image, func = resetbackgroundcolor)]