def MENUmain(): return (("Welcome to", ("REDWALLET", RED), "", "Please select", "an operation"), ((pygbutton.PygButton( (0, 180, 140, 60), 'Create Wallet'), MENUcreateWallet), (pygbutton.PygButton( (180, 180, 140, 60), 'Sign Transaction'), MENUsignTransaction)))
def __init__(self, config, bus, octopi_client, printer): PanelView.__init__(self, config, bus) self.printer = printer self.octopi_client = octopi_client self.fntText = pygame.font.Font( os.path.join(self.config.script_directory, "assets/Roboto-Regular.ttf"), 60) self.fntRegText = pygame.font.Font( os.path.join(self.config.script_directory, "assets/Roboto-Regular.ttf"), 12) # Start, stop and pause buttons self.start_button_image = os.path.join(self.config.script_directory, 'assets/button-start.png') self.pause_button_image = os.path.join(self.config.script_directory, 'assets/button-pause.png') self.stop_button_image = os.path.join(self.config.script_directory, 'assets/button-stop.png') self.btn_start_print = pygbutton.PygButton( (35, 130, 60, 60), normal=self.start_button_image) self.btn_pause_print = pygbutton.PygButton( (130, 130, 60, 60), normal=self.pause_button_image) self.btn_abort_print = pygbutton.PygButton( (225, 130, 60, 60), normal=self.stop_button_image)
def queType(event, screen, T): bg_main = pygame.image.load("QImages\\quizbg.jpg") screen.blit(bg_main, (0, 0)) screen.blit( FONT.render( 'Choose a Topic to Answer a Question and Proceed to Next Level!', True, (0, 0, 0)), (70, 70)) type1 = pygbutton.PygButton((300, 200, 200, 30), T[0], bgcolor=(255, 154, 141)) type2 = pygbutton.PygButton((300, 300, 200, 30), T[1], bgcolor=(255, 154, 141)) type3 = pygbutton.PygButton((300, 400, 200, 30), T[2], bgcolor=(255, 154, 141)) type1.draw(screen) type2.draw(screen) type3.draw(screen) buttonEvent1 = type1.handleEvent(event) buttonEvent2 = type2.handleEvent(event) buttonEvent3 = type3.handleEvent(event) if 'down' in buttonEvent1: return T[0] elif 'down' in buttonEvent2: return T[1] elif 'down' in buttonEvent3: return T[2]
def __init__(self): self.bg_image = pygame.image.load('data/background2.png') self.active_colors = BLACK, DKRED self.inactive_colors = DKRED, BLACK self.music_on_button = pygbutton.PygButton((650, 200, 60, 50), 'ON') self.music_off_button = pygbutton.PygButton((730, 200, 80, 50), 'OFF') self.effects_on_button = pygbutton.PygButton((650, 260, 60, 50), 'ON') self.effects_off_button = pygbutton.PygButton((730, 260, 80, 50), 'OFF') self.return_button = pygbutton.PygButton((0, 550, 300, 50), 'Main Menu') font = pygame.font.Font('data/Kremlin.ttf', 40) self.bg_font = font.render('Music:', True, DKRED) self.se_font = font.render('Sound:', True, DKRED) main_menu = (0, 550, 300, 50) sound_on = (650, 260, 60, 50) music_on = (650, 200, 60, 50) music_off = (730, 200, 80, 50) sound_off = (730, 260, 80, 50) self.selection_box_row_properties = [[main_menu, sound_on, music_on], [main_menu, sound_off, music_off]] row1_initial = 0 if AUDIO.sound_on else 1 row2_initial = 0 if AUDIO.music_on else 1 self.selection_box_col_indices = [0, row1_initial, row2_initial] self.selection_box_row = 0
def __init__(self, width=800, height=600): pygame.init() self.width, self.height = width, height self.screen = pygame.display.set_mode((self.width, self.height)) self.clock = pygame.time.Clock() self.thestage = pygbutton.PygButton((325, 75, 150, 50), 'The Stage') self.thestage.bgcolor = Color('green') self.cliffs = pygbutton.PygButton((325, 175, 150, 50), 'Cliffs of Dover') self.cliffs.bgcolor = Color('red') self.hail = pygbutton.PygButton((325, 275, 150, 50), 'Hail to the King') self.hail.bgcolor = Color('yellow') self.peace = pygbutton.PygButton((325, 375, 150, 50), 'Peace of Mind') self.peace.bgcolor = Color('blue') self.choose = pygbutton.PygButton((325, 475, 150, 50), 'Choose a File...') self.choose.bgcolor = Color('orange') self.font = pygame.font.Font('freesansbold.ttf', 20) self.joysticks = [] for i in range(0, pygame.joystick.get_count()): self.joysticks.append(pygame.joystick.Joystick(i)) self.joysticks[-1].init() print "Detected joystick '", self.joysticks[-1].get_name(), "'"
def __init__(self, width=800, height=600): pygame.init() self.width, self.height = width, height self.screen = pygame.display.set_mode((self.width, self.height)) self.clock = pygame.time.Clock() self.slowride = pygbutton.PygButton((300, 75, 200, 50), 'Top Gun Anthem (Easy)') self.slowride.bgcolor = Color('green') self.jukebox = pygbutton.PygButton((300, 175, 200, 50), 'Top Gun Anthem (Expert)') self.jukebox.bgcolor = Color('red') self.topgun = pygbutton.PygButton((300, 275, 200, 50), 'Top Gun Anthem (Hard)') self.topgun.bgcolor = Color('yellow') self.hail = pygbutton.PygButton((300, 375, 200, 50), 'Hail to the King (Expert)') self.hail.bgcolor = Color('blue') self.choose = pygbutton.PygButton((300, 475, 200, 50), 'Choose a File...') self.choose.bgcolor = Color('orange') self.font = pygame.font.Font('freesansbold.ttf', 20) self.joysticks = [] for i in range(0, pygame.joystick.get_count()): self.joysticks.append(pygame.joystick.Joystick(i)) self.joysticks[-1].init() print "Detected joystick '",self.joysticks[-1].get_name(),"'"
def __init__(self, config, bus, client): PanelView.__init__(self, config, bus) self.client = client self.jog_amount = 10 self.btn_left = pygbutton.PygButton( (2, 92, 50, 50), normal=self.image_path('assets/control-arrow-left.png')) self.btn_right = pygbutton.PygButton( (102, 92, 50, 50), normal=self.image_path('assets/control-arrow-right.png')) self.btn_up = pygbutton.PygButton( (52, 42, 50, 50), normal=self.image_path('assets/control-arrow-up.png')) self.btn_down = pygbutton.PygButton( (52, 142, 50, 50), normal=self.image_path('assets/control-arrow-down.png')) self.btn_z_up = pygbutton.PygButton( (180, 42, 50, 50), normal=self.image_path('assets/control-arrow-up.png')) self.btn_z_down = pygbutton.PygButton( (180, 142, 50, 50), normal=self.image_path('assets/control-arrow-down.png')) self.btn_x_home = pygbutton.PygButton( (260, 42, 50, 50), normal=self.image_path('assets/home-x.png')) self.btn_y_home = pygbutton.PygButton( (260, 92, 50, 50), normal=self.image_path('assets/home-y.png')) self.btn_z_home = pygbutton.PygButton( (260, 142, 50, 50), normal=self.image_path('assets/home-z.png')) self.client = client
def ending(condition): '''ending of the game, allows for quit or restart, displays highscores''' smallfont = pygame.font.SysFont('Comic Sans MS', 60) if condition =='destroyedgreenhouse': deathmsg = smallfont.render('you destroyed a non-target! Score: %d'%score, False, black) elif condition =='outofammo': deathmsg = smallfont.render('you ran out of ammo! Score: %d'%score, False, black) #different death message based on how the player lost addhighscore(playername, score) #first add current high score so that if it is top five it will be displayed highscores = gethighscores() restart = pygbutton.PygButton((850, 300, 300, 100), 'Restart') quit = pygbutton.PygButton((850, 500, 300, 100), 'Quit') score999 = smallfont.render('Highscores:', False, green)# the title "Highscores:" score0 = smallfont.render('1 '+highscores[0], False, green) score1 = smallfont.render('2 ' +highscores[1], False, green) score2 = smallfont.render('3 '+highscores[2], False, green) score3 = smallfont.render('4 '+highscores[3], False, green) score4 = smallfont.render('5 '+highscores[4], False, green) #the top five highscores while(True): screen.fill((255,255,255)) events = pygame.event.get() for event in events: if event.type == pygame.QUIT: exit() if 'click' in restart.handleEvent(event): reset()#reset the values for score and shots intro() if 'click' in quit.handleEvent(event): sys.exit() if(event.type == pygame.KEYDOWN): if(event.key == pygame.K_ESCAPE): sys.exit() screen.blit(deathmsg, (30, 60)) restart.draw(screen) quit.draw(screen) screen.blit(score999, (50, 180)) screen.blit(score0, (80, 280)) screen.blit(score1, (80, 360)) screen.blit(score2, (80, 440)) screen.blit(score3, (80, 520)) screen.blit(score4, (80, 600)) #draw everything pygame.display.update()
def mainMenu(): #Locally initialise the screen screen = pygame.display.set_mode((800, 600), 0, 32) #Generate font objects as well as initialise and display text font = pg.font.SysFont("Calibri", 85, bold=True) newfont = pg.font.SysFont("Calibri", 35, bold=True) header = font.render("MASTERCHEF VRBH", 1, black) text = font.render("BARGAIN HUNT", 1, black) groupnames = newfont.render("BY MAX, MICHAEL, NKOSILATHI, NAMAR AND ISAAC", 1, black) #Generate buttons play = pygbutton.PygButton((350, 300, 100, 30), "PLAY") options = pygbutton.PygButton((350, 370, 100, 30), "OPTIONS") exitgame = pygbutton.PygButton((350, 440, 100, 30), "EXIT") #Responds to events such as pressing the escape key while True: for event in pygame.event.get(): if event.type == QUIT: pygame.quit() sys.exit() if event.type == KEYDOWN: if event.key == K_ESCAPE or event.key == K_q: pygame.quit() sys.exit() if 'click' in exitgame.handleEvent(event): pygame.quit() sys.exit() #if 'click' in play.handleEvent(event): pygame.mixer.music.stop() #Stop music then play another song or no song at all #then do something else once the user clicks play if 'click' in options.handleEvent(event): Options() #display stuff on the screen and continuously update it screen.blit(background, (0, 0)) pygame.draw.rect( screen, white, (60, 50, 690, 55)) #Generate a rectangle and display it on the screen pygame.draw.rect(screen, white, (130, 120, 530, 55)) pygame.draw.rect(screen, white, (15, 530, 775, 35)) screen.blit(header, (60, 40)) screen.blit(text, (130, 110)) screen.blit(firstimage, (5, 200)) screen.blit(secondimage, (495, 200)) screen.blit(groupnames, (15, 530)) play.draw(screen) options.draw(screen) exitgame.draw(screen) pygame.display.update()
def update(): screen.fill((255, 255, 255)) pygame.draw.rect(screen, (255, 0, 0), (225, 50, health, 30)) pygame.draw.rect(screen, (0, 0, 0), (225, 50, 150, 30), 2) pygame.draw.rect(screen, (0, 255, 0), (225, 0, money, 30)) pygame.draw.rect(screen, (0, 0, 0), (225, 0, 150, 30), 2) buttonObj = pygbutton.PygButton((100, 325, 100, 50), questions[qnum].ans1) buttonObj2 = pygbutton.PygButton((400, 325, 100, 50), questions[qnum].ans2) text = font.render(questions[qnum].prompt, True, (0, 0, 0)) buttonObj.draw(screen) buttonObj2.draw(screen) screen.blit(text, textRect)
def quiz(event, screen, que="<question>", options=["option1", "option2", "option3", "option4"], length=200): Q = splitQ(que) Qfont = pygame.font.SysFont('Corbel', 30, bold=True) for i in range(len(Q)): text = Qfont.render(Q[i], True, (0, 0, 0)) screen.blit(text, (25, 20 + 30 * i)) font = pygame.font.SysFont('Corbel', 20, bold=True) answer1 = pygbutton.PygButton((100, 260, length, 30), options[0], font=font, bgcolor=(174, 214, 220)) answer2 = pygbutton.PygButton((100, 300, length, 30), options[1], font=font, bgcolor=(174, 214, 220)) answer3 = pygbutton.PygButton((100, 340, length, 30), options[2], font=font, bgcolor=(174, 214, 220)) answer4 = pygbutton.PygButton((100, 380, length, 30), options[3], font=font, bgcolor=(174, 214, 220)) answer1.draw(screen) answer2.draw(screen) answer3.draw(screen) answer4.draw(screen) buttonEvent1 = answer1.handleEvent(event) buttonEvent2 = answer2.handleEvent(event) buttonEvent3 = answer3.handleEvent(event) buttonEvent4 = answer4.handleEvent(event) if 'down' in buttonEvent1: return options[0] elif 'down' in buttonEvent2: return options[1] elif 'down' in buttonEvent3: return options[2] elif 'down' in buttonEvent4: return options[3]
def inicio(): global gameList,gameOver, screen, tamaño, sizeSquare, tamPlantilla, size, newGameButton, saveGameButton, solveGameButton, Fuente, FuenteG, colScreen #Rutina de inicializacion print("Desea cargar un tablero guardado? S/N ") cargar = input("- ") if str(cargar).capitalize() == "S": gameList = loadFile() print(str(type(gameList))) pprint.pprint(gameList) if type(gameList) == list: print("Tablero cargado con exito") tamaño = len(gameList) else: tamaño = int(eval(input("Tamaño del tablero: "))) gameList = kakuroMaker.kakuroMaker(tamaño).getNewBoard() #generate() print("Desea guardar el tablero nuevo? S/N ") guardar = input("- ") if guardar == "S": saveFile(gameList) pprint.pprint(gameList) #Configuracion de pantalla sizeSquare = 650 // tamaño tamPlantilla = tamaño * sizeSquare size = (tamPlantilla, tamPlantilla + 50) newGameButton = pygbutton.PygButton((10, tamPlantilla + 5, 200, 40), 'Generar nuevo', redP, colScreen, Fuente) saveGameButton = pygbutton.PygButton((tamPlantilla / 2 - 100, tamPlantilla + 5, 200, 40), 'Guardar juego', greenP, colScreen, Fuente) solveGameButton = pygbutton.PygButton((tamPlantilla / 2 + 110, tamPlantilla + 5, 200, 40), 'Resolver juego', blueP, colScreen, Fuente) fontSize = sizeSquare // 3 Fuente = pygame.font.Font(None, fontSize) FuenteG = pygame.font.Font(None, fontSize) screen = pygame.display.set_mode(size) pygame.init() pygame.display.set_caption("KA-KUR-OH!") # pygame.display.set_caption("Grid on PYGAME") clock = pygame.time.Clock() while not gameOver: for event in pygame.event.get(): if event.type == pygame.QUIT: gameOver = True if 'click' in newGameButton.handleEvent(event): gameList = kakuroMaker.kakuroMaker(tamaño).getNewBoard() #generate() if 'click' in saveGameButton.handleEvent(event): saveFile(gameList) if 'click' in solveGameButton.handleEvent(event): gameList = solveGame() drawGrid() clock.tick(10)
def mainMenu(): #initialise the cursor pygame.mouse.set_visible(True) #Generate font objects as well as initialise and display text font = pg.font.SysFont("Calibri", 45, bold = True) newfont = pg.font.SysFont("Calibri", 35, bold = True) newfont1 = pg.font.SysFont("Calibri", 50, bold = True) greet = newfont1.render("WELCOME, ", 1, (250,0,255)) user = newfont1.render(name, 1, (250,0,0)) header = font.render(" TO MASTERCHEF VRBH", 1, (200,50,55)) text = font.render("BARGAIN HUNT", 1, (0,0,255)) groupnames = newfont.render("BY MAX, MICHAEL, NKOSILATHI, NAMAR AND ISAAC", 1, (250,0,0)) #Generate buttons play = pygbutton.PygButton((350, 300, 100, 30), "Play") exitgame = pygbutton.PygButton((350, 370, 100, 30), "Exit") #Responds to events such as pressing the escape key while True: for event in pygame.event.get(): if event.type == QUIT: pygame.quit() sys.exit() if event.type == KEYDOWN: if event.key == K_ESCAPE or event.key == K_q: sys.exit() if 'click' in exitgame.handleEvent(event): pygame.quit() sys.exit() if 'click' in play.handleEvent(event): optionsScreen() #display stuff on the screen and update it screen.blit(background, (0, 0)) screen.blit(greet, (20, 30)) screen.blit(user, (255, 30)) screen.blit(header, (60, 80)) screen.blit(text, (130, 120)) screen.blit(firstimage, (5,200)) screen.blit(secondimage, (495,200)) screen.blit(groupnames, (15, 530)) play.draw(screen) exitgame.draw(screen) pygame.display.update()
def MENUcreateKeys(): if ONPI: os.mkdir('/media/REDKEY') os.mkdir('/media/BLUEKEY') subprocess.check_call('mount', '/dev/sda1', '/media/REDKEY') subprocess.check_call('mount', '/dev/sdb1', '/media/BLUEKEY') wallet_ts = '{0:f}'.format(time.time()) wallet_name = 'redwallet-RED-' + wallet_ts + '_wallet' wallet_path = '/media/REDKEY/' + wallet_name subprocess.check_call('electrum', 'create', '-o', '-w', wallet_path) shutil.copy(wallet_path, '/run') subprocess.check_call('electrum', 'deseed', '-o', '-w', '/run/' + wallet_name) shutil.move('/run/' + wallet_name, '/media/BLUEKEY/redwallet-BLUE-' + wallet_ts + '_wallet') subprocess.check_call('umount', '/media/REDKEY') subprocess.check_call('umount', '/media/BLUEKEY') return ( ("Wallet Created", "", "You can now", "REMOVE", "BOTH KEYS"), ( (pygbutton.PygButton((0, 180, 320, 60), 'OK'), MENUmain), ) # I am a python newb, if you are too, note the trailing comma to create a 1 element tuple )
def __init__(self): self.return_button = pygbutton.PygButton((0, 550, 300, 50), 'Main Menu') self.section_font = pygame.font.Font('data/Kremlin.ttf', 40) self.font = pygame.font.Font('data/arial_narrow_7.ttf', 20) self.bg_image = pygame.image.load('data/help.png') self.bg_title = self.section_font.render('Background', True, WHITE) self.bg_text = textwrap.wrap( 'Under the tyranny of the dark overlord, the world' + 'is in chaos and all the resources are nearly depleted. ' + 'Entire populations have been subjugated to life in labor ' + 'camps, brutally policed by the overlord\'s military forces. ' + 'As your people\'s champion, you must fight to the death in the ' + 'battle arena to win much needed resources.', width=50) self.goals_title = self.section_font.render('Goals', True, WHITE) self.goals_text = textwrap.wrap( 'Ultimately, you want to slay your opponent. ' + 'To become a better fighter, kill the monsters, gain ' + 'experience, and pick up skills. The player to land ' + 'the last hit on the monster will receives the experience ' + 'points. An ultimate boss will spawn every few ' + 'minutes. These bosses drop ultimate skills which ' + 'will help you humiliate and destroy your opponent.', width=50) self.selection_box_properties = [(0, 550, 300, 50)] self.selection_box_i = 0
def __init__(self, x, y, individual, title="", caption="", borderColor=color.BLACK, borderThickness=7, imageType="image"): self.individual = individual self.borderColor = borderColor self.borderThickness = borderThickness self.title = title self.caption = caption self.overlayCaption = "" self.state = self.NONE self.cardRect = pygame.Rect(x, y, 200, 250) self.x = x self.y = y self.fade = False self.symbol = self.NONE if imageType != "": try: self.thumbnail = pygame.transform.scale( individual.images[imageType][random.randint( 0, len(individual.images[imageType]) - 1)], (160, 160)) except TypeError: print("No image found of type %s for individual %s" % (imageType, individual._id)) raise self.imageType = imageType self.button = pygbutton.PygButton((x, y, 200, 250))
def __init__(self, Width, Height): # Initialize the game grid. self.Height = Height self.Width = Width self._FrameRate = 30 self.allPlayers = [] # Initialize pyGame. pygame.init() pygame.display.set_caption("Battle Bikes") self._Clock = pygame.time.Clock() self._Screen = pygame.display.set_mode((self.Width, self.Height)) self._Background = pygame.Surface(self._Screen.get_size()) self._Background.fill(Color.BLACK) self.randColor = Color.WHITE self.running = True self.gameOver = False self.pause = True self.pauseReset = True self.visMode = True self.loserColor = "A COLOR" self.loser = 10 self.speedTxt = 'test' self.gameResult = 'Match in progress' # self._Menu = pygame.Surface(self.Width//2, self.Height//10) # self._Menu.fill(Color.GRAY) self.DownSpeedButton = pygbutton.PygButton( (self.Width * 0, 0, self.Width / 5, 30), "Slow Down", Color.GREEN) self.UpSpeedButton = pygbutton.PygButton( (self.Width * (1 / 5), 0, self.Width / 5, 30), "Speed Up", Color.GREEN) self.ContButton = pygbutton.PygButton( (self.Width * (2 / 5), 0, self.Width / 5, 30), "Continue", Color.GREEN) self.PlayButton = pygbutton.PygButton( (self.Width * (3 / 5), 0, self.Width / 5, 30), "New Game", Color.GREEN) self.QuitButton = pygbutton.PygButton( (self.Width * (4 / 5), 0, self.Width / 5, 30), "Quit", Color.GREEN) self.menuButtons = (self.UpSpeedButton, self.DownSpeedButton) self.pauseButtons = (self.ContButton, self.QuitButton) self.endButtons = (self.PlayButton, self.QuitButton) self.allButtons = self.menuButtons + self.pauseButtons + self.endButtons
def GetImageButton(self): self.btn = pygbutton.PygButton( (self.posX, self.posY, self.buttonWidth, self.buttonHeight), None, None, None, None, self.normalSurf, self.downSurf, self.highlightSurf, self.name) return self.btn
def __init__(self, width=800, height=600): pygame.init() self.width, self.height = width, height self.screen = pygame.display.set_mode((self.width, self.height)) self.clock = pygame.time.Clock() self.thestage = pygbutton.PygButton((325, 125, 150, 50), 'The Stage') self.thestage.bgcolor = Color('green') self.cliffs = pygbutton.PygButton((325, 225, 150, 50), 'Cliffs of Dover') self.cliffs.bgcolor = Color('red') self.hail = pygbutton.PygButton((325, 325, 150, 50), 'Hail to the King') self.hail.bgcolor = Color('yellow') self.peace = pygbutton.PygButton((325, 425, 150, 50), 'Peace of Mind') self.peace.bgcolor = Color('blue')
def main(): """ The Main function that runs the game loop """ pygame.init() Player_Money = 1000 Jack_Pot = 500 Turn = 1 Bet = 0 Prev_Bet = 0 win_number = 0 loss_number = 0 screen = pygame.display.set_mode((640, 480)) pygame.display.set_caption("The House Always Wins!") background = pygame.Surface(screen.get_size()) background = background.convert() background.fill((5, 5, 5)) clock = pygame.time.Clock() keepGoing = True box = pygame.Surface((560, 390)) box = box.convert() box.fill((235, 230, 230)) box_x = 40 box_y = 40 box1 = pygame.Surface((250, 100)) box1 = box1.convert() box1.fill((55, 55, 55)) box1_x = 100 box1_y = 310 buttonSpin = pygbutton.PygButton((400, 350, 150, 30), 'Spin') buttonReset = pygbutton.PygButton((400, 380, 150, 30), 'Reset') while keepGoing: clock.tick(60) for event in pygame.event.get(): if event.type == pygame.QUIT: keepGoing = False screen.blit(background, (0, 0)) screen.blit(box, (box_x, box_y)) screen.blit(box1, (box1_x, box1_y)) screen.blit(title, (150, 50)) screen.blit(img, (95, 125)) screen.blit(img, (255, 125)) screen.blit(img, (415, 125)) buttonSpin.draw(screen) buttonReset.draw(screen) pygame.display.flip()
def generate_buttons(): buttons = [] for x in range(0, 8): button_row = [] for y in range(0, 8): button_row.append( pygbutton.PygButton((x * square_size, y * square_size, square_size, square_size), "")) buttons.append(button_row) return [buttons]
def __init__(self): self.menu_box = Rect2(topleft=(320, 120), size=(640, 240), color=BLACK) main_font = 'data/Kremlin.ttf' pause_font = pygame.font.Font(main_font, 100) self.pause_font_xy = font_position_center(self.menu_box, pause_font, '-PAUSE-') self.pause_font_rendered = pause_font.render('-PAUSE-', True, RED) self.continue_button_properties = (395, 270, 200, 50) self.quit_button_properties = (730, 270, 100, 50) self.continue_button = pygbutton.PygButton( self.continue_button_properties, 'Continue') self.quit_button = pygbutton.PygButton(self.quit_button_properties, 'Quit') self.selection_box_properties = [ self.continue_button_properties, self.quit_button_properties ] self.selection_box_i = 0
def GetTextButton(self): self.btn = pygbutton.PygButton( (self.posX, self.posY, self.buttonWidth, self.buttonHeight), self.title, self.bgColor, self.fontColor, self.font, None, None, None, self.name) #caption='', bgcolor=LIGHTGRAY, fgcolor=BLACK, font=None, #normal=None, down=None, highlight=None, bName=None return self.btn
def main(): pygame.init() FPSCLOCK = pygame.time.Clock() DISPLAYSURFACE = pygame.display.set_mode((WINDOWWIDTH, WINDOWHEIGHT)) pygame.display.set_caption('PygButton Test 2') buttonHello = pygbutton.PygButton((50, 100, 200, 30), 'Hello') buttonToggleVis = pygbutton.PygButton((50, 50, 200, 30), 'Toggle Button Visibility') if platform.system() == 'Windows': buttonHello.font = pygame.font.SysFont( 'comicsansms', 20) # Unfortunately, this line will only work on Windows machines. visMode = True while True: # main game loop buttonHello.visible = visMode #pygame.display.update() for event in pygame.event.get(): # event handling loop if event.type == QUIT or (event.type == KEYDOWN and event.key == K_ESCAPE): pygame.quit() sys.exit() events = buttonToggleVis.handleEvent(event) if 'click' in events: visMode = not visMode buttonHello.visible = visMode #why has to call the following command??: buttonHello.handleEvent(event) #DISPLAYSURFACE.fill(WHITE) DISPLAYSURFACE.fill(WHITE) buttonToggleVis.draw(DISPLAYSURFACE) buttonHello.draw(DISPLAYSURFACE) #DISPLAYSURFACE.fill(WHITE) pygame.display.update() FPSCLOCK.tick(FPS)
def init_buttons(self): self.buttons.append( pygbutton.PygButton((self.width - 50, 0, 50, 50), 'T', font=self.boxy_bold_25)) self.buttons.append( pygbutton.PygButton((self.width - 150, self.height - 200, 50, 50), '<', font=self.boxy_bold_25)) self.buttons.append( pygbutton.PygButton((self.width - 100, self.height - 250, 50, 50), '^', font=self.boxy_bold_25)) self.buttons.append( pygbutton.PygButton((self.width - 100, self.height - 150, 50, 50), 'v', font=self.boxy_bold_25)) self.buttons.append( pygbutton.PygButton((self.width - 50, self.height - 200, 50, 50), '>', font=self.boxy_bold_25))
def generate_buttons(squares_x, squares_y, square_size): field_buttons = [] clicked_buttons = [] for x in range(0, squares_x): button_row = [] clicked_button_row = [] for y in range(0, squares_y): button_row.append(pygbutton.PygButton((x * square_size, y * square_size + 48, square_size, square_size), "")) clicked_button_row.append(False) field_buttons.append(button_row) clicked_buttons.append(clicked_button_row) return [field_buttons, clicked_buttons]
def generate_buttons(x_pos, y_pos, size): field_buttons = [] clicked_buttons = [] for x in range(0, x_pos): button_row = [] clicked_button_row = [] for y in range(0, y_pos): button_row.append( pygbutton.PygButton((x * size, y * size, size, size), "")) clicked_button_row.append(False) field_buttons.append(button_row) clicked_buttons.append(clicked_button_row) return [field_buttons, clicked_buttons]
def main(): # pixels per grid # also works as the scaling factor. k = 25 # active is set to True when the program is running. active = True # mouse motion is not needed. Blocking mouse move saves processor. pygame.event.set_blocked(MOUSEMOTION) # creates "New Equation" button btnNewEquation = pygbutton.PygButton((width + 10, 60, 200, 30), 'New Equation', (100, 100, 255)) while active: # updating the screen clearScreen(screen) # clear screen graphpaper(k) # draw graph paper draw_equations(k) # draw equations drawTitle(screen) # draw title screen.set_clip(None) # paints the button on to the screen btnNewEquation.draw(screen) # lists all the equations on the screen listEquations(screen) # repaints the screen # Update portions of the screen for software displays pygame.display.update() # wait for an event event = pygame.event.wait() if event.type == pygame.QUIT: # set active to False and get out of the main loop active = False if 'click' in btnNewEquation.handleEvent(event): # btnNewEquation click event listener new_equation_handler() # pygame.time.wait(20) # exits the program pygame.quit()
def initButtons(self): x = self.buttonStartX y = self.buttonStartY numButtons = self.stageModel.numButtons answerButtons = [] for i in range(numButtons): indPath = self.stageModel.indList[i].imagepath indCate = self.stageModel.indList[i].category answerButtons.append( pygbutton.PygButton((x, y, 0, 0), normal=indPath, value=indCate)) x += 200 if x == 1250: x = 350 y = 550 return answerButtons
def main(): pygame.init() FPSCLOCK = pygame.time.Clock() DISPLAYSURFACE = pygame.display.set_mode((WINDOWWIDTH, WINDOWHEIGHT)) pygame.display.set_caption('PygButton Test 3') catButt = pygbutton.PygButton((50, 100, 200, 30), normal='catbutton_normal.png', down='catbutton_down.png', highlight='catbutton_highlight.png') while True: # main game loop for event in pygame.event.get(): # event handling loop if event.type == QUIT or (event.type == KEYDOWN and event.key == K_ESCAPE): pygame.quit() sys.exit() buttonEvents = catButt.handleEvent(event) if 'click' in buttonEvents: catButt.rect = pygame.Rect((catButt.rect.left, catButt.rect.top, catButt.rect.width + 10, catButt.rect.height + 10)) DISPLAYSURFACE.fill(WHITE) catButt.draw(DISPLAYSURFACE) pygame.display.update() FPSCLOCK.tick(FPS)