import pygame from pygame import font import gui #PYGAME INITIALIZATION AND EXTRA STUFF pygame.init() screen = pygame.display.set_mode((800,600), pygame.DOUBLEBUF) clock = pygame.time.Clock() run = True back = pygame.image.load('art/back.jpg').convert() #END #GUI STUFF #This way it's easy to load the example gui skin: import picbunStyle picbunStyle.init(gui) #First, we create a desktop to contain all the widgets desktop = gui.Desktop() #Create a label passing some parameters. #TRICKY THING HERE: if you want to use an already defined style, just copy it, and set new parameters as you wish labelStyleCopy = gui.defaultLabelStyle.copy() labelStyleCopy['border-width'] = 1 labelStyleCopy['wordwrap'] = True labelStyleCopy['autosize'] = False label = gui.Label(position = (50,60),size = (200,100), parent = desktop, text = "Click the button for a proverb!", style = labelStyleCopy) #Create the button button = gui.Button(position = (50,165), size = (200,200), parent = desktop, text = "Teach me!") button2 = gui.Button(position = (50, 190), size = (200,0), parent = desktop, text = "Quit") button2.onClick = lambda button:pygame.quit() #Let's create a window button3 = gui.Button(position = (50, 220), size = (200,0), parent = desktop, text = "Demo Window") button3.count = 0 def button3_onClick(button): button.count += 1 win = gui.Window(position = (300,220), size = (400,200), parent = desktop, text = "Window %d" % button.count) gui.Label(position = (10,40), parent = win, text = "Write something in the textbox") win.textbox = gui.TextBox(position = (10, 60), parent = win) gui.CheckBox(position = win.nextPosition(5), parent = win, text = 'Do something') gui.CheckBox(position = win.nextPosition(1), parent = win, text = 'Do something') gui.CheckBox(position = win.nextPosition(1), parent = win, text = 'Do something') b = gui.Button(position = (310,70), size = (80,0) , parent= win, text = "Say it!") b.onClick = lambda button :gui.Label(position = (10,30), text = win.textbox.text, parent = gui.Window(size = (win.textbox.textWidth + 20,50), parent = desktop, text = "Hello World")) button3.onClick = button3_onClick #Let's create a window button4 = gui.Button(position = (300, 165), size = (200,0), parent = desktop, text = "Callbacks Window") def button4_onClick(button): win = gui.Window(position = (300,220), size = (400,200), parent = desktop, text = "A Callback Window") gui.Label(position = (10,40), parent = win, text = "Move the window or shade it.") def changeTitle(text): def temp(window): window.text=text return temp win.onMove=changeTitle('I\'m Moving!') win.onMoveStop=changeTitle('I\'m Not Moving!') win.onShade=changeTitle('I\'m Shaded!') win.onUnshade=changeTitle('I\'m Not Shaded!') win.onClose= lambda button :gui.Label(position = (10,30), text = 'You closed my favorite window', parent = gui.Window(size = (200,50), parent = desktop, text = "Sob")) button4.onClick = button4_onClick #Textbox txt = gui.TextBox(position = (50,250), size = (200, 0), parent = desktop, text = "What a wonderful") #Checkbox chk = gui.CheckBox(position = (50,290), size = (200,40), parent = desktop, text = "Check me if you can") def onChkValueChanged(chk): button3.enabled = chk.value chk.onValueChanged = onChkValueChanged gui.OptionBox(position = desktop.nextPosition(5), parent = desktop, text = "Option 1", value = True) gui.OptionBox(position = desktop.nextPosition(1), parent = desktop, text = "Option 2") gui.OptionBox(position = desktop.nextPosition(1), parent = desktop, text = "Option 3") def itemSelected(widget): label.text = "You selected the row number " + str(widget.selectedIndex) gui.ListBox(position = desktop.nextPosition(5), size = (150, 100), parent = desktop, items =["Row number %d" % i for i in range(10)]).onItemSelected = itemSelected #EXECUTION while run: clock.tick() gui.display.set_caption(str(int(clock.get_fps()))) #Just for exit for e in gui.setEvents(): #pygame.event.get()): if e.type == pygame.QUIT: run = False #UPDATE YOUR LOGIC BEFORE UPDATING THE GUI #... #The desktop should be the last thing you update (for performance reasons) #First let the gui know events occurred #Then update the desktop you're using desktop.update() #Here begins rendering screen.fill((20,40,50)) #YOUR RENDERING HERE!!! screen.blit(back, (0,0)) #END CUSTOM RENDERING #Last thing to draw, desktop desktop.draw() #Flips! pygame.display.flip() #Bye bye pygame.quit()