def init_board(self): board = [] for x in range(0, self.screen_size, self.screen_size // 9): for y in range(0, self.screen_size, self.screen_size // 9): # Draw border of the squares if x % 3 == 0 and y % 3 == 0: pygame.draw.rect( self.screen, color.GRAY, Rect(x + self.border, y + self.border, self.squares[0], self.squares[0])) num = self.sudoku.board[x // 100][y // 100] # Create input boxes if num > 0: inputbox = InputBox(x, y, self.squares[1], self.squares[1], self.border, str(num), True) else: inputbox = InputBox(x, y, self.squares[1], self.squares[1], self.border) # Append new InputBox into an array board.append(inputbox) return board
def printhelp(self, grid, start, secs): helpfile = open('pygamehelp') inbox = InputBox(self.screen, boxw=260, boxh=220, cb=self.pstats, cbargs=(grid, start, secs)) val = inbox.show(helpfile.read()) if val: if val.type == pygame.QUIT: return 'quit'
def changename(self, name): if not name: name = '' inbox = InputBox(self.screen) cnresult = inbox.ask("Level Name", text=name) if not cnresult: return if type(cnresult) is not str: if cnresult.type == pygame.QUIT: return ('control', 'quit') return cnresult
def AddItem(self, sender, e): input = InputBox() result = input.ShowDialog() if result == DialogResult.OK: text = input._textBox.Text if text: mesgresult = MessageBox.Show( text + " will be added to the BlackList.\n\nWould you also like to remove any occurences of this publisher from the already downloaded data?\n\n(Clicking Cancel will not add this publisher to the BlackList)", "Delete existing?", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question) if mesgresult == DialogResult.Yes: self._blacklistdisplay.Items.Add(text) self.ComicList.RemovePublisher(text) elif mesgresult == DialogResult.No: self._blacklistdisplay.Items.Add(text) input.Dispose()
def show_popup(task, textPosition): Log("Open Pop up input screen") background = SCREEN.copy() input = InputBox((360,268), BUFFER, color=[(179,179,179),(0,186,220),(179,179,179)],font_color=FONT_COLOR_POPUP, max_size=280, enable_rows = False) input.makeFocus() text = pygame.font.Font( FONT, FONT_SIZE ).render(task , True, (0,0,0) ) running = True while running: mouseX, mouseY = pygame.mouse.get_pos() CLEAR(BUFFER) SCREEN.blit(background,(0,0)) SCREEN.blit(PIC_POPUP,(0,0)) SCREEN.blit(text,textPosition) SCREEN.blit(PIC_OK_BTN_UP, (393, 300)) SCREEN.blit(PIC_CANCEL_BTN_UP, (520, 300)) for event in pygame.event.get(): if event.type == pygame.QUIT: if show_security(): sys.exit() if event.type == pygame.KEYDOWN: if event.key == pygame.K_RETURN: running = False #Left mouseclick on OK button if event.type == pygame.MOUSEBUTTONDOWN and mouse_in_area(mouseX, mouseY, 393, 300, 87, 28) and event.button == 1: SCREEN.blit(PIC_OK_BTN_DOWN, (393, 300)) if event.type == pygame.MOUSEBUTTONUP and mouse_in_area(mouseX, mouseY, 393, 300, 87, 28) and event.button == 1: running = False #Left mouseclick on CANCEL button if event.type == pygame.MOUSEBUTTONDOWN and mouse_in_area(mouseX, mouseY, 520, 300, 87, 28) and event.button == 1: SCREEN.blit(PIC_CANCEL_BTN_DOWN, (520, 300)) if event.type == pygame.MOUSEBUTTONUP and mouse_in_area(mouseX, mouseY, 520, 300, 87, 28) and event.button == 1: return None input.handleEvent(event) input.update(SCREEN) pygame.display.update() return input.getString()
def question(q, pos, size=(300, 50), fontsize=fontSize, allowanswer=1, default='', waitForAnswer=1): qsurf = InputBox(screen, pos, size, q, allowanswer, fontsize=fontsize, a=default) pygame.display.update() finished = 0 answer = None if waitForAnswer: while not finished: for event in pygame.event.get(): finished, answer = qsurf.handle_event(event) qsurf.draw(screen) pygame.display.update() return answer
recv_message(msg_split) else: recv_message(msg) def penalty(queue, t): for i in range(t, 0, -1): queue.put(i) time.sleep(1) queue.put(0) cards_obj = [] Thread(target = sock_recv, args = [clientSocket,input_queue]).start() screen = pygame.display.set_mode((1400, 700)) pygame.draw.rect(screen, (0, 0, 30), pygame.Rect(550, 100, 300, 400 ), 0) pygame.draw.rect(screen, (255, 255, 255), pygame.Rect(550, 100, 300, 400), 1) input_username = InputBox(600, 300, 200, 40, defaultText="username") input_password = InputBox(600, 350, 200, 40, defaultText="password",password=True) login_button = Button(screen,(100, 575), (575, 100), "Login", (250, 0, 0), (0, 0, 30), False, 36) register_button = Button(screen, (725, 575), (575, 100), "Register", (250, 0, 0), (0, 0, 30), False, 36) input_boxes = [input_username,input_password] startScreen(screen,(100, 50), (1200, 500),input_boxes,[login_button,register_button]) while not loggedIn: for event in pygame.event.get(): if event.type == pygame.QUIT: clientSocket.send("QUIT|{}".format(str(user)).encode("utf-8")) clientSocket.close() pygame.quit() sys.exit() for box in input_boxes:
def game_over(): score_list = get_scoreboard() good_run = is_good_run(score_list) large_text = LARGE_FONT.render("Game Over", True, PURPLE) text_rect = large_text.get_rect() text_rect.center = (window_width // 2, window_height // 2 - 100) window.blit(large_text, text_rect) restart_button = Button("Restart", window_width // 2 + 50, 500, 100, 200, PURPLE, GREEN, BLACK, 40) menu_button = Button("Main Menu", window_width // 2 - 250, 500, 100, 200, PURPLE, GREEN, BLACK, 40) if good_run: input_box = InputBox(window_width // 2, 420, 130, 30) text = None name_text = SMALL_FONT.render("Enter your name: ", True, PURPLE) text_rect = name_text.get_rect() text_rect.center = (window_width // 2, window_height // 2) window.blit(name_text, text_rect) while True: for event in pygame.event.get(): if event.type == pygame.QUIT: pygame.quit() quit() text = input_box.handle_event(event) if text: update_scoreboard(score_list, text) input_box.draw(window) mouse_pos = pygame.mouse.get_pos() mouse_clicks = pygame.mouse.get_pressed() restart_button.draw(mouse_pos, window) menu_button.draw(mouse_pos, window) if restart_button.is_clicked(mouse_pos, mouse_clicks): main_game() elif menu_button.is_clicked(mouse_pos, mouse_clicks): game_menu(True) pygame.display.update() clock.tick(15) else: while True: for event in pygame.event.get(): if event.type == pygame.QUIT: pygame.quit() quit() mouse_pos = pygame.mouse.get_pos() mouse_clicks = pygame.mouse.get_pressed() restart_button.draw(mouse_pos, window) menu_button.draw(mouse_pos, window) if restart_button.is_clicked(mouse_pos, mouse_clicks): main_game() elif menu_button.is_clicked(mouse_pos, mouse_clicks): game_menu(True) keys = pygame.key.get_pressed() if keys[pygame.K_r]: main_game() pygame.display.update() clock.tick(15)
coloredlogs.install(level='DEBUG') WIDTH = 1024 HEIGHT = 768 FONT_NAME = "Arial" FONT_SIZE = 36 WIN_CAPTION = "Doomsdash" SERVER_URL = "127.0.0.1" conn_status = b"NOT CONNECTED" conn_color = pynk.lib.nk_rgb(255, 0, 0) tb = NetworkTables.initialize(server=SERVER_URL) #NetworkTables.enableVerboseLogging() d_width = WIDTH d_height = HEIGHT data_box = InputBox(128) def make_screen(): return pygame.display.set_mode((d_width, d_height), pygame.RESIZABLE) def connectionListener(connected, info): logging.info(str(info) + ": Connected={}".format(connected)) if connected: global conn_status global conn_color conn_status = b"CONNECTED" conn_color = pynk.lib.nk_rgb(0, 255, 0) def drawValues(ctx, inValues):