def print_names(screen, names): counter = 0 for y in range(3): for x in range(5): if counter < len(names): textbox.OutputBox( screen=screen, text=names[counter], size=(WIDTH / 6, HEIGHT / 10), place=(5 + x * (WIDTH / 5), int(245 / 600. * HEIGHT) + HEIGHT / 8 * y), color=WHITE, border_width=2, border_color=BLACK, text_color=BLACK, font="dependencies\\files\\montserrat\\Montserrat-Black.otf" ).draw() counter += 1
def exit_screen(screen, names, points): global Running sizes = [85, 85, 85] for i in range(3): answerFont = pygame.font.Font(None, sizes[i]) while answerFont.size(names[i])[0] > int(132 / 800. * WIDTH): sizes[i] -= 1 answerFont = pygame.font.Font(None, sizes[i]) pygame.mixer.music.load(OST_DIR + "winners.mp3") pygame.mixer.music.set_volume(0.8) pygame.mixer.music.play(-1) gif = 0 speed = 1 sub = False finish = False la_finito = False up = 0 last = time.time() start = last final = [350, 386, 419] podioms = [400, 327, 241] while not finish: current = time.time() last = current screen.fill((87, 37, 194)) events = pygame.event.get() for event in events: if event.type == pygame.QUIT: pygame.mixer.music.fadeout(gif * 100) finish = True Running = False exit() if event.type == pygame.KEYDOWN: if event.key == pygame.K_SPACE: if gif > 56: pygame.mixer.music.fadeout(gif * 100) la_finito = True image = pygame.image.load(IMAGES_DIR + "win_background\\frame_%s_delay-0.04s.png" % str(gif % 178).zfill(3)) image = resfix(image) screen.blit(image, (0, up)) speed += 1 if not la_finito: if current - start >= 8: podioms[0] = podioms[0] - 4 if podioms[0] - 4 >= 0 else 0 podioms[2] = podioms[2] - 4 if podioms[2] - 4 >= 0 else 0 podioms[1] = podioms[1] - 4 if podioms[1] - 4 >= 0 else 0 else: podioms = [x + (178 - gif) / 7 for x in podioms] image = pygame.image.load(IMAGES_DIR + "winners_stand\\Slide1.png") image = pygame.transform.scale(image, (WIDTH / 5, int(HEIGHT * 1.3))) screen.blit(image, (int((800 / 2 - 74) / 800. * WIDTH), int((final[0] + podioms[0]) / 600. * HEIGHT))) textbox.OutputBox( screen, str(points[0]) + " points!", (WIDTH / 5 - WIDTH / 25, int(45 / 600. * HEIGHT)), (int((800 / 2 - 74) / 800. * WIDTH + WIDTH / 50), int((final[0] + podioms[0] + 130) / 600. * HEIGHT)), None, 0, None, (255, 255, 255), "dependencies\\files\\montserrat\\Montserrat-Black.otf").draw() textbox.OutputBox( screen, names[0], (WIDTH / 5 - WIDTH / 25, int(80 / 600. * HEIGHT)), (int((800 / 2 - 74) / 800. * WIDTH + WIDTH / 50), int((final[0] + podioms[0]) / 600. * HEIGHT)), None, 0, None, (255, 255, 255), "dependencies\\files\\montserrat\\Montserrat-Black.otf").draw() image = pygame.image.load(IMAGES_DIR + "winners_stand\\Slide2.png") image = pygame.transform.scale(image, (WIDTH / 5, int(HEIGHT * 1.3))) screen.blit(image, (int((800 / 2 - 74 * 4) / 800. * WIDTH), int((final[1] + podioms[1]) / 600. * HEIGHT))) textbox.OutputBox( screen, str(points[1]) + " points!", (WIDTH / 5 - WIDTH / 25, int(45 / 600. * HEIGHT)), (int((800 / 2 - 74 * 4) / 800. * WIDTH + WIDTH / 50), int((final[1] + podioms[1] + 130) / 600. * HEIGHT)), None, 0, None, (255, 255, 255), "dependencies\\files\\montserrat\\Montserrat-Black.otf").draw() textbox.OutputBox( screen, names[1], (WIDTH / 5 - WIDTH / 25, int(80 / 600. * HEIGHT)), (int((800 / 2 - 74 * 4) / 800. * WIDTH + WIDTH / 50), int((final[1] + podioms[1]) / 600. * HEIGHT)), None, 0, None, (255, 255, 255), "dependencies\\files\\montserrat\\Montserrat-Black.otf").draw() image = pygame.image.load(IMAGES_DIR + "winners_stand\\Slide3.png") image = pygame.transform.scale(image, (WIDTH / 5, int(HEIGHT * 1.3))) screen.blit(image, (int((800 / 2 + 74 * 2) / 800. * WIDTH), int((final[2] + podioms[2]) / 600. * HEIGHT))) textbox.OutputBox( screen, str(points[2]) + " points!", (WIDTH / 5 - WIDTH / 25, int(45 / 600. * HEIGHT)), (int((800 / 2 + 74 * 2) / 800. * WIDTH + WIDTH / 50), int((final[2] + podioms[2] + 130) / 600. * HEIGHT)), None, 0, None, (255, 255, 255), "dependencies\\files\\montserrat\\Montserrat-Black.otf").draw() textbox.OutputBox( screen, names[2], (WIDTH / 5 - WIDTH / 25, int(80 / 600. * HEIGHT)), (int((800 / 2 + 74 * 2) / 800. * WIDTH + WIDTH / 50), int((final[2] + podioms[2]) / 600. * HEIGHT)), None, 0, None, (255, 255, 255), "dependencies\\files\\montserrat\\Montserrat-Black.otf").draw() if la_finito: if gif <= 56: if up > -HEIGHT + HEIGHT / 8: up -= 10 else: finish = True gif -= 1 elif gif == 177: sub = True gif -= 1 elif gif > 38: if sub and gif > 94: gif -= 1 else: sub = False gif += 1 else: if gif < 36 or time.time() - start >= 7: gif += 1 pygame.display.flip() if time.time() - start >= 10: clock.tick(10) else: clock.tick(5)
def load_timer( num, screen, question, ): global QuestioNumber, TotalQN, Running QuestioNumber += 1 first = time.time() last = time.time() current = time.time() count = 0 question_text = textbox.OutputBox( screen, question, (WIDTH, int(70 / 600. * HEIGHT)), (0, int(312 / 600. * HEIGHT)), (255, 255, 255), 0, (), (0, 0, 0), "dependencies\\files\\montserrat\\Montserrat-Black.otf") question_id = textbox.OutputBox( screen, "Question " + str(QuestioNumber) + " out of " + str(TotalQN), (WIDTH, int(40 / 600. * HEIGHT)), (0, 0), (255, 255, 255), 0, (), (0, 0, 0), "dependencies\\files\\montserrat\\Montserrat-Black.otf") finish = False while current - first <= num + 0.4 and not finish: events = pygame.event.get() for event in events: if event.type == QUIT: Running = False exit() return True if event.type == pygame.KEYDOWN: # If pressed key is ESC quit program if event.key == pygame.K_ESCAPE: Running = False exit() return True #if event.type == pygame.KEYDOWN: # if event.key == pygame.K_SPACE: # finish = True current = time.time() if current - last > 0.05: hamster_img = pygame.image.load(IMAGES_DIR + "loading\\hamster\\Slide%s.png" % str(count / 2 % 12 + 1)) size = hamster_img.get_rect().size hamster_img = pygame.transform.scale( hamster_img, (int(size[0] / 800. * WIDTH), int(size[1] / 600. * HEIGHT))) image = pygame.image.load( IMAGES_DIR + "loading\wheel\\frame_%s_delay-0.04s.png" % str(19 - (count % 19)).zfill(2)) size = image.get_rect().size image = pygame.transform.scale( image, (int(size[0] / 800. * WIDTH), int(size[1] / 600. * HEIGHT))) image.set_colorkey((0, 0, 0)) screen.blit(BLACKSURFACE, (0, 0)) x = 20 # width of a letter, change according to the font question_text.draw() screen.blit(hamster_img, (int(340 / 800. * WIDTH), int(50 / 600. * HEIGHT))) screen.blit(image, (int(300 / 800. * WIDTH), int(95 / 600. * HEIGHT))) bar = pygame.Surface((int( (current - first) / num * WIDTH), int(60 / 600. * HEIGHT))) bar.fill((124, 0, 255)) barop = pygame.Surface((WIDTH - int( (current - first - 0.3) / num * WIDTH) if WIDTH - int( (current - first) / num * WIDTH) > 0 else 0, int(60 / 600. * HEIGHT))) barop.fill((188, 135, 243)) screen.blit(barop, (int( (current - first - 0.3) / num * WIDTH), int( 400 / 600. * HEIGHT))) screen.blit(bar, (0, int(400 / 600. * HEIGHT))) question_id.draw() pygame.display.flip() last = current count += 1 return False
def show_answer(screen, res, correct_answer, question, photo): global Running res_sum = max(res) if max(res) else 1 rc = pygame.image.load(IMAGES_DIR + "main\\red_correct.png") rc = resfix(rc) bc = pygame.image.load(IMAGES_DIR + "main\\blue_correct.png") bc = resfix(bc) yc = pygame.image.load(IMAGES_DIR + "main\\orange_correct.png") yc = resfix(yc) gc = pygame.image.load(IMAGES_DIR + "main\\green_correct.png") gc = resfix(gc) inrc = pygame.image.load(IMAGES_DIR + "main\\red_incorrect.png") inrc = resfix(inrc) inbc = pygame.image.load(IMAGES_DIR + "main\\blue_incorrect.png") inbc = resfix(inbc) inyc = pygame.image.load(IMAGES_DIR + "main\\orange_incorrect.png") inyc = resfix(inyc) ingc = pygame.image.load(IMAGES_DIR + "main\\green_incorrect.png") ingc = resfix(ingc) red = inrc blue = inbc yellow = inyc green = ingc if correct_answer == 1: red = rc if correct_answer == 2: blue = bc if correct_answer == 3: yellow = yc if correct_answer == 4: green = gc addedimg = None if photo: addedimg = pygame.transform.scale( pygame.image.load("./dependencies/files/temp." + photo), (int( (665 - 143) / 800. * WIDTH), int((334 - 70) / 600. * HEIGHT))) a = [3, 367, 403, 367, 3, 484, 403, 484] Rstartx, Rstarty, Bstartx, Bstarty, Ystartx, Ystarty, Gstartx, Gstarty = [ int(a[x] / 800. * WIDTH) if x % 2 == 0 else int(a[x] / 600. * HEIGHT) for x in range(len(a)) ] questionFont = pygame.font.Font( "dependencies\\files\\montserrat\\Montserrat-Black.otf", 50) question_text = textbox.OutputBox( screen, question, (WIDTH, int(70 / 600. * HEIGHT)), (0, 0), (255, 255, 255), 0, (), (0, 0, 0), "dependencies\\files\\montserrat\\Montserrat-Black.otf") Sx = 60.0 / res_sum # scale of moving according to the amount of answers in x Sy = 25.0 / res_sum # scale of moving according to the amount of answers in y c = 0 finish = False pygame.mixer.music.set_volume(1) time.sleep(0.05) pygame.mixer.music.load(OST_DIR + "answers.mp3") pygame.mixer.music.play(1) last = time.time() while not finish: events = pygame.event.get() for event in events: if event.type == pygame.QUIT: Running = False exit() return True if event.type == pygame.KEYDOWN: # If pressed key is ESC quit program if event.key == pygame.K_ESCAPE: Running = False exit() return True if event.type == pygame.KEYDOWN: if event.key == pygame.K_SPACE: return False screen.fill(WHITE) pygame.draw.circle(screen, (201, 14, 163), (int(723 / 800. * WIDTH), int(206 / 600. * HEIGHT)), 30) pygame.draw.circle(screen, (201, 14, 163), (int(74 / 800. * WIDTH), int(206 / 600. * HEIGHT)), 30) width = int(395 / 800. * WIDTH) #width of the rectengels height = int(111 / 600. * HEIGHT) #height of the rectrngels if time.time() - last > 0.1: last = time.time() """Green rectengles""" Rrect1 = pygame.draw.polygon( screen, (11, 87, 4), [(Gstartx, Gstarty), (Gstartx + width, Gstarty), (int(Gstartx + Sx * c * res[3] + width), int(Gstarty + Sy * c * res[3])), (int(Gstartx + Sx * c * res[3]), int(Gstarty + Sy * c * res[3]))]) Rrect2 = pygame.draw.polygon( screen, (29, 233, 12), [(Gstartx, Gstarty), (Gstartx, Gstarty + height), (int(Gstartx + Sx * c * res[3]), int(Gstarty + Sy * c * res[3] + height)), (int(Gstartx + Sx * c * res[3]), int(Gstarty + Sy * c * res[3]))]) screen.blit(green, (Gstartx + res[3] * Sx * c, Gstarty + res[3] * Sy * c)) amount = questionFont.render(str(int(res[3] * c)), False, WHITE) screen.blit(amount, (Gstartx + 130 + Sx * c * res[3], Gstarty + 40 + Sy * c * res[3])) """"Yellow rectengles""" Rrect1 = pygame.draw.polygon( screen, (128, 80, 0), [(Ystartx, Ystarty), (Ystartx + width, Ystarty), (int(Ystartx + Sx * c * res[2] + width), int(Ystarty + Sy * c * res[2])), (int(Ystartx + Sx * c * res[2]), int(Ystarty + Sy * c * res[2]))]) Rrect2 = pygame.draw.polygon( screen, (254, 172, 35), [(Ystartx, Ystarty), (Ystartx, Ystarty + height), (int(Ystartx + Sx * c * res[2]), int(Ystarty + Sy * c * res[2] + height)), (int(Ystartx + Sx * c * res[2]), int(Ystarty + Sy * c * res[2]))]) screen.blit(yellow, (Ystartx + res[2] * Sx * c, Ystarty + res[2] * Sy * c)) amount = questionFont.render(str(int(res[2] * c)), False, WHITE) screen.blit(amount, (Ystartx + 130 + Sx * c * res[2], Ystarty + 40 + Sy * c * res[2])) """Blue rectengles""" Rrect1 = pygame.draw.polygon( screen, (1, 23, 75), [(Bstartx, Bstarty), (Bstartx + width, Bstarty), (int(Bstartx + Sx * c * res[1] + width), int(Bstarty + Sy * c * res[1])), (int(Bstartx + Sx * c * res[1]), int(Bstarty + Sy * c * res[1]))]) Rrect2 = pygame.draw.polygon( screen, (54, 114, 252), [(Bstartx, Bstarty), (Bstartx, Bstarty + height), (int(Bstartx + Sx * c * res[1]), int(Bstarty + Sy * c * res[1] + height)), (int(Bstartx + Sx * c * res[1]), int(Bstarty + Sy * c * res[1]))]) screen.blit(blue, (Bstartx + res[1] * Sx * c, Bstarty + res[1] * Sy * c)) amount = questionFont.render(str(int(res[1] * c)), False, WHITE) screen.blit(amount, (Bstartx + 130 + Sx * c * res[1], Bstarty + 40 + Sy * c * res[1])) """red rectengles""" Rrect1 = pygame.draw.polygon( screen, (106, 3, 0), [(Rstartx, Rstarty), (Rstartx + width, Rstarty), (int(Rstartx + Sx * c * res[0] + width), int(Rstarty + Sy * c * res[0])), (int(Rstartx + Sx * c * res[0]), int(Rstarty + Sy * c * res[0]))]) Rrect2 = pygame.draw.polygon( screen, (255, 44, 38), [(Rstartx, Rstarty), (Rstartx, Rstarty + height), (int(Rstartx + Sx * c * res[0]), int(Rstarty + Sy * c * res[0] + height)), (int(Rstartx + Sx * c * res[0]), int(Rstarty + Sy * c * res[0]))]) screen.blit(red, (Rstartx + res[0] * Sx * c, Rstarty + res[0] * Sy * c)) amount = questionFont.render(str(int(res[0] * c)), False, WHITE) screen.blit(amount, (Rstartx + 130 + Sx * c * res[0], Rstarty + 40 + Sy * c * res[0])) question_text.draw() if addedimg: screen.blit(addedimg, (int(143 / 800. * WIDTH), int(75 / 600. * HEIGHT))) else: textbox.OutputBox( screen, text=" KABOOT! ", size=(int((665 - 143) / 800. * WIDTH), int((334 - 75) / 600. * HEIGHT)), place=(int(143 / 800. * WIDTH), int(75 / 600. * HEIGHT)), color=(201, 14, 163), text_color=WHITE, font="dependencies\\files\\montserrat\\Montserrat-Black.otf" ).draw() pygame.display.flip() c = c + 0.1 if c + 0.1 <= 1 else 1 return False
def main(QUIZ): global users, QuestioNumber, TotalQN, Running, Title, screen Server.initiate() Title = QUIZ threading.Thread(target=handle_clients).start() screen = pygame.display.set_mode((0, 0), pygame.FULLSCREEN) #screen = pygame.display.set_mode((800, 600)) done = False #"""the playes exited the game?""" start_game = False # the game has started? pygame.init() # initiate pygames pygame.display.set_caption("Kaboot") pygame.display.flip() pygame.font.init() a = textbox.OutputBox( screen, QUIZ, (WIDTH, int(100 / 600. * HEIGHT)), (0, int(50 / 600. * HEIGHT)), (255, 255, 255), 0, (), (0, 0, 0), "dependencies\\files\\montserrat\\Montserrat-Black.otf") b = textbox.OutputBox( screen, "No Users Logged In", (WIDTH, int(50 / 600. * HEIGHT)), (0, int(175 / 600. * HEIGHT)), (255, 255, 255), 0, (), (0, 0, 0), "dependencies\\files\\montserrat\\Montserrat-Black.otf") c = textbox.OutputBox( screen, "Start", (int(770 / 800. * WIDTH - 25 / 800. * WIDTH), int(580 / 600. * HEIGHT - 490 / 600. * HEIGHT)), (int(25 / 800. * WIDTH), int(490 / 600. * HEIGHT)), (255, 255, 255), 0, (0, 0, 0), (0, 0, 0), "dependencies\\files\\montserrat\\Montserrat-Black.otf") prev_users = Server.update_login() #gets list of names print_names(screen, prev_users) #prints the name to the screen users = None mouse_loc = (0, 0) pygame.mixer.init() pygame.mixer.music.load(OST_DIR + "login.mp3") pygame.mixer.music.play(-1) trying = 0 time.sleep(0.5) first = 2 while not start_game and not done: #while game was not exited and game is still at the log in part events = pygame.event.get() """checks events, user input""" for event in events: #checks for events including: if event.type == MouseMotion: #mouse hovering above the start button x, y = event.pos mouse_loc = event.pos if event.type == pygame.QUIT: #user presses the X done = True Running = False exit() if event.type == pygame.KEYDOWN: # If pressed key is ESC quit program if event.key == pygame.K_ESCAPE: done = True Running = False exit() if event.type == MouseButtonDown: #player clicks the screen(should be only button) if event.button == 1: x, y = event.pos if not first: if 25 / 800. * WIDTH < x and x < 770 / 800. * WIDTH and y > 490 / 600. * HEIGHT and y < 580 / 600. * HEIGHT: # if mouse above start button start_game = True else: first -= 1 """"load screen""" screen.fill((35, 177, 76)) for topstart in [x * int(WIDTH / 10) for x in range(20)]: pygame.draw.line(screen, (176, 235, 48), (trying + topstart, -10), (-10, trying + topstart), int(0.0125 * WIDTH)) x, y = mouse_loc #gets mouse location if 25 / 800. * WIDTH < x and x < 770 / 800. * WIDTH and y > 490 / 600. * HEIGHT and y < 580 / 600. * HEIGHT: # if mouse above start button= a.draw() b.draw() c.border_width = 6 c.draw() pygame.mouse.set_cursor( *pygame.cursors.broken_x) # set cursor to broken x else: a.draw() b.draw() c.border_width = 0 c.draw() pygame.mouse.set_cursor( *pygame.cursors.arrow) # set cursor to an arrow users = Server.update_login() #gets updated list of names if users: if len(users) == 1: b.text = str(len(users)) + " User Logged In" else: b.text = str(len(users)) + " Users Logged In" else: b.text = "No Users Logged In" """update list""" if users != prev_users: for user in users: already_in = False for prev_user in prev_users: if user == prev_user: already_in = True if not already_in: prev_users = [user] + prev_users for prev_user in prev_users: already_in = False for user in users: if user == prev_user: already_in = True if not already_in: prev_users.remove(prev_user) print_names(screen, prev_users) pygame.display.flip() trying += 1 if trying == WIDTH / 10: trying = 0 clock.tick(60) pygame.mouse.set_cursor(*pygame.cursors.arrow) with open("dependencies\\quizes\\" + QUIZ + '.json', 'rb') as qfile: quiz = json.load(qfile) #with open(IMAGES_DIR+"Example.jpg", 'rb') as img: # quiz['Questions'][0]['photo'] = base64.b64encode(img.read()) #with open('quizes/test.json', 'wb') as qfile: # json.dump(quiz, qfile, indent=4) pygame.mixer.music.fadeout(quiz['Questions'][0]['time to read'] * 1000) TotalQN = len(quiz['Questions']) first = True for q in quiz['Questions']: add_question(screen, q['time to read'], q['question'], [x.encode("utf-8") for x in q['answers']], q['correct answer'], q['photo'], q['image file type'], q['time to answer'], q['points'], first) first = False Server.end_game() names = Server.get_players() players = [x[1] for x in names] points = [x[0] for x in names] while len(players) < 3: players.append("None") points.append(0) exit_screen(screen, players, points) pygame.quit() time.sleep(0.2) Running = False exit()
def load_question(screen, question, photo, answers, qtime): """ :param screen: gets screen to print on :param question: gets the question :param photo: gets a photo if there is one :param answers: gets all possible answers :param correct_answer: gets the number of the correct answer :param qtime: gets the time for the question :param qpoints: gets maximum points for answering the question :return: Did player exit the game """ global users, Running # image rc = pygame.image.load(IMAGES_DIR + "main\\red_correct.png") rc = resfix(rc) bc = pygame.image.load(IMAGES_DIR + "main\\blue_correct.png") bc = resfix(bc) yc = pygame.image.load(IMAGES_DIR + "main\\orange_correct.png") yc = resfix(yc) gc = pygame.image.load(IMAGES_DIR + "main\\green_correct.png") gc = resfix(gc) a = [0, 367, 403, 367, 0, 484, 403, 484] Rstartx, Rstarty, Bstartx, Bstarty, Ystartx, Ystarty, Gstartx, Gstarty = [ int(a[x] / 800. * WIDTH) if x % 2 == 0 else int(a[x] / 600. * HEIGHT) for x in range(len(a)) ] addedimg = None if photo: addedimg = pygame.transform.scale( pygame.image.load("./dependencies/files/temp." + photo), (int( (665 - 143) / 800. * WIDTH), int((334 - 70) / 600. * HEIGHT))) # question question_text = textbox.OutputBox( screen, question, (WIDTH, int(70 / 600. * HEIGHT)), (0, 0), (255, 255, 255), 0, (), (0, 0, 0), "dependencies\\files\\montserrat\\Montserrat-Black.otf") # time start_time = time.time() time_passed = time.time() - start_time answer_boxes = [] for y in range(4): answer_boxes.append( textbox.OutputBox( screen, text=answers[y], size=(int(335 / 800. * WIDTH), int(105 / 600. * HEIGHT)), place=(int(int(60 / 800. * WIDTH) + (WIDTH / 2) * (y % 2)), int(372 / 600. * HEIGHT) + int(120 / 600. * HEIGHT) * int(y / 2)), color=None, text_color=WHITE, font="dependencies\\files\\montserrat\\Montserrat-Black.otf")) timerText = textbox.OutputBox( screen, text=str(qtime), size=(int( (753 - 693 - 6) / 800. * WIDTH), int((235 - 175) / 600. * HEIGHT)), place=(int((43 + 3) / 800. * WIDTH), int(175 / 600. * HEIGHT)), color=None, text_color=WHITE, font="dependencies\\files\\montserrat\\Montserrat-Black.otf") timerTextHeader = textbox.OutputBox( screen, text=" Seconds:", size=(int(142 / 800. * WIDTH), int((237 - 177 + 100) / 600. * HEIGHT)), place=(0, int(177 / 600. * HEIGHT) - int( (237 - 177 + 50) / 600. * HEIGHT)), color=None, text_color=BLACK, font="dependencies\\files\\montserrat\\Montserrat-Black.otf") answerText = textbox.OutputBox( screen, text=str(0), size=(int( (753 - 693 - 6) / 800. * WIDTH), int((235 - 175) / 600. * HEIGHT)), place=(int((693 + 3) / 800. * WIDTH), int(175 / 600. * HEIGHT)), color=None, text_color=WHITE, font="dependencies\\files\\montserrat\\Montserrat-Black.otf") answerTextHeader = textbox.OutputBox( screen, text="Answers: ", size=(int( (800 - 664) / 800. * WIDTH), int( (235 - 175 + 100) / 600. * HEIGHT)), place=(int(664 / 800. * WIDTH), int(175 / 600. * HEIGHT) - int( (235 - 175 + 50) / 600. * HEIGHT)), color=None, text_color=BLACK, font="dependencies\\files\\montserrat\\Montserrat-Black.otf") pygame.mixer.music.load(OST_DIR + "question.mp3") pygame.mixer.music.set_volume(0.4) pygame.mixer.music.play(-1) answers_amount = 0 while time_passed < qtime and answers_amount < len(users): events = pygame.event.get() answers_amount = Server.receive() for event in events: if event.type == pygame.QUIT: pygame.mixer.music.stop() Running = False exit() return True if event.type == pygame.KEYDOWN: # If pressed key is ESC quit program if event.key == pygame.K_ESCAPE: Running = False exit() return True screen.fill(WHITE) pygame.draw.circle(screen, (201, 14, 163), (int(723 / 800. * WIDTH), int(206 / 600. * HEIGHT)), 30) pygame.draw.circle(screen, (201, 14, 163), (int(74 / 800. * WIDTH), int(206 / 600. * HEIGHT)), 30) if addedimg: screen.blit(addedimg, (int(143 / 800. * WIDTH), int(75 / 600. * HEIGHT))) else: textbox.OutputBox( screen, text=" KABOOT! ", size=(int( (665 - 143) / 800. * WIDTH), int( (334 - 75) / 600. * HEIGHT)), place=(int(143 / 800. * WIDTH), int(75 / 600. * HEIGHT)), color=(201, 14, 163), text_color=WHITE, font="dependencies\\files\\montserrat\\Montserrat-Black.otf" ).draw() screen.blit(rc, (Rstartx, Rstarty)) screen.blit(bc, (Bstartx, Bstarty)) screen.blit(yc, (Ystartx, Ystarty)) screen.blit(gc, (Gstartx, Gstarty)) #check_for_place(screen, events) # question question_text.draw() # answers for answer in answer_boxes: answer.draw() # timer time_passed = time.time() - start_time timerText.text = str(int(qtime - time_passed)) timerText.draw() timerTextHeader.draw() answerText.text = str( int(answers_amount)) if answers_amount is not None else "0" answerText.draw() answerTextHeader.draw() pygame.display.flip() pygame.mixer.music.stop() return False
def score_board(screen, players, next_round_points): global Running image = pygame.image.load(IMAGES_DIR + "scoreboard\\scoreboard.png") image = resfix(image) # time start_time = time.time() #print players finish = False header = textbox.OutputBox(screen, "Scoreboard", (WIDTH, int(80 / 600. * HEIGHT)), (0, int(10 / 600. * HEIGHT)), (255, 255, 255), 0, (), (0, 0, 0), "dependencies\\files\\RosewoodStd-Regular.otf") users = [] for i in range(5): if not i and players: users.append( textbox.OutputBox( screen, players[i][1] + " - " + str(players[i][0]) + " points", (int(700 / 800. * WIDTH), int(70 / 600. * HEIGHT)), (int(50 / 800. * WIDTH), int(120 / 600. * HEIGHT)), (255, 255, 255), 3, (0, 0, 0), (0, 0, 0), FONT_LIB + "ALGER.TTF")) elif i < len(players): users.append( textbox.OutputBox( screen, players[i][1] + " - " + str(players[i][0]) + " points", (int(700 / 800. * WIDTH), int(70 / 600. * HEIGHT)), (int(50 / 800. * WIDTH), int((70 * i + 20 + 120) / 600. * HEIGHT)), (), 3, (0, 0, 0), (0, 0, 0), FONT_LIB + "ALGER.TTF")) under = textbox.OutputBox( screen, "Next round reward - " + str(next_round_points) + " points!", (int(650 / 800. * WIDTH), int(75 / 600. * HEIGHT)), (int(75 / 800. * WIDTH), int(525 / 600. * HEIGHT)), (163, 73, 163), 0, (), (255, 255, 255), "dependencies\\files\\montserrat\\Montserrat-Black.otf") while not finish: events = pygame.event.get() for event in events: if event.type == pygame.QUIT: Running = False exit() return True if event.type == pygame.KEYDOWN: # If pressed key is ESC quit program if event.key == pygame.K_ESCAPE: Running = False exit() return True if event.type == pygame.KEYDOWN: if event.key == pygame.K_SPACE: finish = True if event.key == pygame.K_p: print pygame.mouse.get_pos() screen.blit(image, (0, 0)) header.draw() for user in users: user.draw() under.draw() pygame.display.flip() return False
def imaging(screen, file, background): global quiz background = background.convert() background.set_alpha(20) question_text = textbox.OutputBox( screen, "Use + and - to change the image's scale.\nUse the mouse to move the image.", (WIDTH, int(75 / 600. * HEIGHT)), (0, 0), (0, 0, 0), 0, (), (255, 255, 255), "dependencies\\files\\montserrat\\Montserrat-Black.otf") doneb = textbox.ButtonBox( screen, "Done", (int(770 / 800. * WIDTH - 25 / 800. * WIDTH), int(580 / 600. * HEIGHT - 490 / 600. * HEIGHT)), (int(25 / 800. * WIDTH), int(490 / 600. * HEIGHT)), (255, 255, 255), 5, (0, 0, 0), (0, 0, 0), "dependencies\\files\\montserrat\\Montserrat-Black.otf") frame = textbox.OutputBox( screen, text="", size=(int((665 - 143) / 800. * WIDTH), int( (334 - 75) / 600. * HEIGHT)), place=(int(143 / 800. * WIDTH), int(75 / 600. * HEIGHT)), color=None, text_color=WHITE, font="dependencies\\files\\montserrat\\Montserrat-Black.otf", border_width=4, border_color=(255, 255, 255)) image = pygame.image.load(file) place = frame.place size = image.get_size() resize = (1, 1) if size[0] > size[1]: if size[0] > WIDTH: resize = (1. * WIDTH / size[0], 1. * WIDTH / size[0]) else: if size[1] > HEIGHT: resize = (1. * HEIGHT / size[1], 1. * HEIGHT / size[1]) finished = False mouseinit = None while not finished: x, y = pygame.mouse.get_pos() events = pygame.event.get() for event in events: if event.type == pygame.QUIT: exit() return True if event.type == pygame.KEYDOWN: # If pressed key is ESC quit program if event.key == pygame.K_ESCAPE: exit() return True screen.fill((0, 0, 0)) screen.blit(background, (0, 0)) pressed = pygame.key.get_pressed() s, t = resize[0], resize[1] for key in pressed: if key: if pressed.index(1) == 45: t = resize[1] - 0.005 if resize[1] - 0.005 > 0 else t s = resize[0] - 0.005 if resize[0] - 0.005 > 0 else s if pressed.index(1) == 61: t = resize[1] + 0.01 s = resize[0] + 0.01 resize = (s, t) if size[0] * resize[0] < frame.size[ 0] and not size[1] * resize[1] < frame.size[1]: place = (int(frame.place[0] + frame.size[0] / 2 - (size[0] * resize[0]) / 2.), place[1]) if place[1] > frame.place[1]: place = (place[0], frame.place[1]) if place[1] + size[1] * resize[1] < frame.place[1] + frame.size[1]: place = (place[0], frame.place[1] - (size[1] * resize[1] - frame.size[1])) elif size[1] * resize[1] < frame.size[ 1] and not size[0] * resize[0] < frame.size[0]: place = (place[0], int(frame.place[1] + frame.size[1] / 2 - (size[1] * resize[1]) / 2.)) if place[0] > frame.place[0]: place = (frame.place[0], place[1]) if place[0] + size[0] * resize[0] < frame.place[0] + frame.size[0]: place = (frame.place[0] - (size[0] * resize[0] - frame.size[0]), place[1]) elif size[0] * resize[0] < frame.size[ 0] and size[1] * resize[1] < frame.size[1]: place = (int(frame.place[0] + frame.size[0] / 2 - (size[0] * resize[0]) / 2.), int(frame.place[1] + frame.size[1] / 2 - (size[1] * resize[1]) / 2.)) else: if size[0] * resize[0] > frame.size[0]: if place[1] + size[1] * resize[1] < frame.place[ 1] + frame.size[1]: place = (place[0], frame.place[1] - (size[1] * resize[1] - frame.size[1])) if size[1] * resize[1] > frame.size[1]: if place[0] + size[0] * resize[0] < frame.place[ 0] + frame.size[0]: place = (frame.place[0] - (size[0] * resize[0] - frame.size[0]), place[1]) image = pygame.transform.scale( pygame.image.load(file), (int(size[0] * resize[0]), int(size[1] * resize[1]))) if pygame.mouse.get_pressed()[0] and (not doneb.is_highlighted() or mouseinit): if not mouseinit: mouseinit = (x - place[0], y - place[1]) else: if size[0] * resize[0] < frame.size[ 0] and not size[1] * resize[1] < frame.size[1]: place = (int(frame.place[0] + frame.size[0] / 2 - (size[0] * resize[0]) / 2.), y - mouseinit[1]) if place[1] > frame.place[1]: place = (place[0], frame.place[1]) if place[1] + size[1] * resize[1] < frame.place[ 1] + frame.size[1]: place = (place[0], frame.place[1] - (size[1] * resize[1] - frame.size[1])) elif size[1] * resize[1] < frame.size[ 1] and not size[0] * resize[0] < frame.size[0]: place = (x - mouseinit[0], int(frame.place[1] + frame.size[1] / 2 - (size[1] * resize[1]) / 2.)) if place[0] > frame.place[0]: place = (frame.place[0], place[1]) if place[0] + size[0] * resize[0] < frame.place[ 0] + frame.size[0]: place = (frame.place[0] - (size[0] * resize[0] - frame.size[0]), place[1]) elif size[0] * resize[0] < frame.size[ 0] and size[1] * resize[1] < frame.size[1]: pass else: place = (x - mouseinit[0], y - mouseinit[1]) if place[1] > frame.place[1]: place = (place[0], frame.place[1]) if place[1] + size[1] * resize[1] < frame.place[ 1] + frame.size[1]: place = (place[0], frame.place[1] - (size[1] * resize[1] - frame.size[1])) if place[0] > frame.place[0]: place = (frame.place[0], place[1]) if place[0] + size[0] * resize[0] < frame.place[ 0] + frame.size[0]: place = (frame.place[0] - (size[0] * resize[0] - frame.size[0]), place[1]) else: mouseinit = None if mouseinit: doneb.border_color = None else: doneb.border_color = (0, 0, 0) screen.blit(image, place) frame.draw() doneb.draw() question_text.draw() finished = doneb.was_clicked() and not mouseinit pygame.display.flip() screen.fill((255, 255, 255)) screen.blit(image, place) time.sleep(0.1) camera = screen.subsurface( pygame.Rect( (frame.place[0], frame.place[1], frame.size[0], frame.size[1]))) pygame.image.save(camera, "dependencies\\files\\temp.jpg")
def load_question(screen, question, photo, answers, qtime, points, rtime, QuestioNumber): """ :param screen: gets screen to print on :param question: gets the question :param photo: gets a photo if there is one :param answers: gets all possible answers :param correct_answer: gets the number of the correct answer :param qtime: gets the time for the question :param qpoints: gets maximum points for answering the question :return: Did player exit the game """ global users, quiz # image rc = pygame.image.load(IMAGES_DIR + "main\\red_correct.png") rc = pygame.transform.scale(rc, (396, 112)) bc = pygame.image.load(IMAGES_DIR + "main\\blue_correct.png") bc = pygame.transform.scale(bc, (396, 112)) yc = pygame.image.load(IMAGES_DIR + "main\\orange_correct.png") yc = pygame.transform.scale(yc, (396, 112)) gc = pygame.image.load(IMAGES_DIR + "main\\green_correct.png") gc = pygame.transform.scale(gc, (396, 112)) sx, sy = (396, 112) a = [0, 367, 403, 367, 0, 484, 403, 484] Rstartx, Rstarty, Bstartx, Bstarty, Ystartx, Ystarty, Gstartx, Gstarty = [ int(a[x] / 800. * WIDTH) if x % 2 == 0 else int(a[x] / 600. * HEIGHT) for x in range(len(a)) ] addedimg = None if photo: addedimg = pygame.transform.scale( pygame.image.load("./dependencies/files/temp." + photo), (int( (665 - 143) / 800. * WIDTH), int((334 - 75) / 600. * HEIGHT))) imgbutt = textbox.ButtonBox(screen, text="", place=(int(143 / 800. * WIDTH), int(75 / 600. * HEIGHT)), size=(int((665 - 143) / 800. * WIDTH), int((334 - 75) / 600. * HEIGHT)), color=None, text_color=(0, 0, 0), border_color=(0, 0, 0), border_width=2, mouse=False) uploadimg = pygame.transform.scale( pygame.image.load(IMAGES_DIR + "icons\\upload_image.png"), (int((665 - 143) / 800. * WIDTH / 4), int((334 - 70 + 60) / 600. * HEIGHT / 3))) uploadimgbutt = textbox.ButtonBox( screen, text="", place=(int(143 / 800. * WIDTH) + int( (665 - 143) / 800. * WIDTH) * 0.55, int(75 - 20 / 600. * HEIGHT) + int( (334 - 70) / 600. * HEIGHT) * 0.3), size=(int((665 - 143) / 800. * WIDTH / 4), int((334 - 70 + 60) / 600. * HEIGHT / 3)), color=None, text_color=(0, 0, 0), border_color=None, border_width=0) delimg = pygame.transform.scale( pygame.image.load(IMAGES_DIR + "icons\\x.png"), (int( (665 - 143) / 800. * WIDTH / 4), int( (334 - 70) / 600. * HEIGHT / 3))) delimgbutt = textbox.ButtonBox( screen, text="", place=(int(143 / 800. * WIDTH) + int( (665 - 143) / 800. * WIDTH) * 0.20, int(75 / 600. * HEIGHT) + int( (334 - 70) / 600. * HEIGHT) * 0.3), size=(int( (665 - 143) / 800. * WIDTH / 4), int( (334 - 70) / 600. * HEIGHT / 3)), color=None, text_color=(0, 0, 0), border_color=None, border_width=0) previmg = addedimg # question question_text = textbox.InputBox( screen, (WIDTH, int(70 / 600. * HEIGHT)), (0, 0), (255, 255, 255), 0, (), (0, 0, 0), "dependencies\\files\\montserrat\\Montserrat-Black.otf", False, question) # Number OutOf = textbox.OutputBox( screen, text="Question " + str(QuestioNumber + 1) + " out of " + str(TotalQN), size=(WIDTH, int(372 / 600. * HEIGHT) - int(75 / 600. * HEIGHT) - int( (334 - 70) / 600. * HEIGHT)), place=(0, int(75 / 600. * HEIGHT) + int((334 - 75) / 600. * HEIGHT)), color=None, text_color=BLACK, font="dependencies\\files\\montserrat\\Montserrat-Black.otf") answer_boxes = [] for y in range(4): answer_boxes.append( textbox.InputBox( screen, placeholder=answers[y], size=(int(335 / 800. * WIDTH), int(105 / 600. * HEIGHT)), place=(int(int(60 / 800. * WIDTH) + (WIDTH / 2) * (y % 2)), int(372 / 600. * HEIGHT) + int(120 / 600. * HEIGHT) * int(y / 2)), color=None, text_color=WHITE, font="dependencies\\files\\montserrat\\Montserrat-Black.otf")) TimeToReadQ = textbox.OutputBox( screen, text=" Seconds\nto read:", size=(int(140 / 800. * WIDTH), int((296 / 6) / 600. * HEIGHT)), place=(int(2 / 800. * WIDTH), int((70) / 600. * HEIGHT)), color=None, text_color=BLACK, font="dependencies\\files\\montserrat\\Montserrat-Black.otf") TimeToReadA = textbox.InputBox( screen, size=(int(140 / 800. * WIDTH), int((296 / 6) / 600. * HEIGHT)), place=(int(2 / 800. * WIDTH), int((70 + 298 / 6) / 600. * HEIGHT)), color=WHITE, text_color=BLACK, border_color=BLACK, border_width=2, font="dependencies\\files\\montserrat\\Montserrat-Black.otf", numeric=True, placeholder=str(rtime)) TimeToAnswerQ = textbox.OutputBox( screen, text=" Seconds\nto answer:", size=(int(140 / 800. * WIDTH), int((296 / 6) / 600. * HEIGHT)), place=(int(2 / 800. * WIDTH), int((70 + int( (296 / 6) / 600. * HEIGHT) * 2 + 5) / 600. * HEIGHT)), color=None, text_color=BLACK, font="dependencies\\files\\montserrat\\Montserrat-Black.otf") TimeToAnswerA = textbox.InputBox( screen, size=(int(140 / 800. * WIDTH), int((296 / 6) / 600. * HEIGHT)), place=(int(2 / 800. * WIDTH), int((70 + int((296 / 6) / 600. * HEIGHT) * 2 + 298 / 6 + 5) / 600. * HEIGHT)), color=WHITE, text_color=BLACK, border_color=BLACK, border_width=2, font="dependencies\\files\\montserrat\\Montserrat-Black.otf", numeric=True, placeholder=str(qtime)) prev = textbox.ButtonBox( screen, text="<-", size=(int( (753 - 693 - 6) / 800. * WIDTH), int((235 - 175) / 600. * HEIGHT)), place=(int((43 + 3) / 800. * WIDTH), int((366 - (235 - 170) - 20) / 600. * HEIGHT)), color=None, text_color=WHITE, border_color=None, font="dependencies\\files\\montserrat\\Montserrat-Black.otf") if QuestioNumber == 0: prev.text = "" PointsQ = textbox.OutputBox( screen, text=" Reward:", size=(int(132 / 800. * WIDTH), int((296 / 6) / 600. * HEIGHT)), place=(int(666 / 800. * WIDTH), int((70) / 600. * HEIGHT)), color=None, text_color=BLACK, font="dependencies\\files\\montserrat\\Montserrat-Black.otf") PointsA = textbox.InputBox( screen, size=(int(132 / 800. * WIDTH), int((296 / 6) / 600. * HEIGHT)), place=(int(666 / 800. * WIDTH), int((70 + 298 / 6) / 600. * HEIGHT)), color=WHITE, text_color=BLACK, border_color=BLACK, border_width=2, font="dependencies\\files\\montserrat\\Montserrat-Black.otf", numeric=True, placeholder=str(points)) DeleteQuestion = textbox.ButtonBox( screen, text="Delete Question", size=(int(132 / 800. * WIDTH), int((296 / 6) / 600. * HEIGHT)), place=(int(666 / 800. * WIDTH), int((70 + int( (296 / 6) / 600. * HEIGHT) * 2 + 5) / 600. * HEIGHT)), color=(201, 14, 163), text_color=WHITE, border_color=None, border_width=2, font="dependencies\\files\\montserrat\\Montserrat-Black.otf") BackToHomeScreen = textbox.ButtonBox( screen, text="Back To\nHome Screen", size=(int(132 / 800. * WIDTH), int((296 / 6) / 600. * HEIGHT)), place=(int(666 / 800. * WIDTH), int((70 + int((296 / 6) / 600. * HEIGHT) * 2 + 298 / 6 + 5) + 5 / 600. * HEIGHT)), color=(201, 14, 163), text_color=WHITE, border_color=None, border_width=2, font="dependencies\\files\\montserrat\\Montserrat-Black.otf") next = textbox.ButtonBox( screen, text="->", size=(int( (753 - 693 - 6) / 800. * WIDTH), int((235 - 175) / 600. * HEIGHT)), place=(int((693 + 3) / 800. * WIDTH), int((366 - (235 - 170) - 20) / 600. * HEIGHT)), color=None, text_color=WHITE, border_color=None, font="dependencies\\files\\montserrat\\Montserrat-Black.otf") if QuestioNumber == TotalQN - 1: next.text = "NEW" rb = textbox.ButtonBox(screen, text="", place=(9, 397), size=(44, 41), color=None, text_color=(0, 0, 0), border_color=None) bb = textbox.ButtonBox(screen, text="", place=(411, 395), size=(46, 46), color=None, text_color=(0, 0, 0), border_color=None) yb = textbox.ButtonBox(screen, text="", place=(10, 516), size=(46, 46), color=None, text_color=(0, 0, 0), border_color=None) gb = textbox.ButtonBox(screen, text="", place=(414, 519), size=(45, 43), color=None, text_color=(0, 0, 0), border_color=None) regretometer = 0 wtf = False idk = False counter = 3 changes = False while True: events = pygame.event.get() for event in events: if event.type == pygame.QUIT: exit() return True if event.type == pygame.KEYDOWN: # If pressed key is ESC quit program if event.key == pygame.K_ESCAPE: exit() return True screen.fill(WHITE) pygame.draw.circle( screen, (201, 14, 163), (int(723 / 800. * WIDTH), int( (366 - 30 - 20) / 600. * HEIGHT)), 30) pygame.draw.circle( screen, (201, 14, 163), (int(74 / 800. * WIDTH), int((366 - 30 - 20) / 600. * HEIGHT)), 30) if addedimg: screen.blit(addedimg, (int(143 / 800. * WIDTH), int(75 / 600. * HEIGHT))) else: textbox.OutputBox( screen, text=" KABOOT! ", size=(int( (665 - 143) / 800. * WIDTH), int( (334 - 75) / 600. * HEIGHT)), place=(int(143 / 800. * WIDTH), int(75 / 600. * HEIGHT)), color=(201, 14, 163), text_color=WHITE, font="dependencies\\files\\montserrat\\Montserrat-Black.otf" ).draw() if quiz["Questions"][QuestioNumber]["correct answer"] == 1: pygame.draw.rect(screen, (29, 161, 29), (Rstartx, Rstarty, sx, sy)) screen.blit(rc, (Rstartx, Rstarty)) if quiz["Questions"][QuestioNumber]["correct answer"] == 2: pygame.draw.rect(screen, (29, 161, 29), (Bstartx, Bstarty, sx, sy)) screen.blit(bc, (Bstartx, Bstarty)) if quiz["Questions"][QuestioNumber]["correct answer"] == 3: pygame.draw.rect(screen, (29, 161, 29), (Ystartx, Ystarty, sx, sy)) screen.blit(yc, (Ystartx, Ystarty)) if quiz["Questions"][QuestioNumber]["correct answer"] == 4: pygame.draw.rect(screen, (29, 161, 29), (Gstartx, Gstarty, sx, sy)) screen.blit(gc, (Gstartx, Gstarty)) # question question_text.draw() if question_text.get_input() != quiz["Questions"][QuestioNumber][ "question"] and not question_text.is_toggled(): quiz["Questions"][QuestioNumber][ "question"] = question_text.get_input() changes = True #print "1" # answers numbbbbbbb = 0 for answer in answer_boxes: answer.draw() if answer.get_input() != quiz["Questions"][QuestioNumber][ "answers"][numbbbbbbb] and not answer.is_toggled(): quiz["Questions"][QuestioNumber]["answers"][ numbbbbbbb] = answer.get_input() changes = True #print "2" numbbbbbbb += 1 OutOf.draw() for button in [BackToHomeScreen, prev, next, DeleteQuestion]: if button.is_highlighted(): button.text_color = BLACK else: button.text_color = WHITE TimeToAnswerQ.draw() TimeToAnswerA.draw() if TimeToAnswerA.get_input() and int( TimeToAnswerA.get_input()) != quiz["Questions"][QuestioNumber][ "time to answer"] and not TimeToAnswerA.is_toggled(): quiz["Questions"][QuestioNumber]["time to answer"] = int( TimeToAnswerA.get_input()) changes = True #print "3" TimeToReadQ.draw() TimeToReadA.draw() if TimeToReadA.get_input() and int( TimeToReadA.get_input()) != quiz["Questions"][QuestioNumber][ "time to read"] and not TimeToReadA.is_toggled(): quiz["Questions"][QuestioNumber]["time to read"] = int( TimeToReadA.get_input()) changes = True #print "4" prev.draw() PointsQ.draw() PointsA.draw() if PointsA.get_input() and int( PointsA.get_input()) != quiz["Questions"][QuestioNumber][ "points"] and not PointsA.is_toggled(): quiz["Questions"][QuestioNumber]["points"] = int( PointsA.get_input()) changes = True #print "5" BackToHomeScreen.draw() DeleteQuestion.draw() next.draw() rb.draw() bb.draw() yb.draw() gb.draw() if rb.was_clicked(): quiz["Questions"][QuestioNumber]["correct answer"] = 1 changes = True #print "6" if bb.was_clicked(): quiz["Questions"][QuestioNumber]["correct answer"] = 2 changes = True #print "7" if yb.was_clicked(): quiz["Questions"][QuestioNumber]["correct answer"] = 3 changes = True #print "8" if gb.was_clicked(): quiz["Questions"][QuestioNumber]["correct answer"] = 4 changes = True #print "9" if next.was_clicked(): return QuestioNumber + 1 if prev.text and prev.was_clicked(): return QuestioNumber - 1 if BackToHomeScreen.was_clicked(): time.sleep(0.1) return -1 if DeleteQuestion.was_clicked() and TotalQN > 1: quiz['Questions'].remove(quiz['Questions'][QuestioNumber]) #print "updated" with open('dependencies/quizes/' + Title + '.json', 'wb') as qfile: json.dump(quiz, qfile, indent=4) if QuestioNumber < TotalQN - 1: return QuestioNumber else: return QuestioNumber - 1 imgbutt.draw() if imgbutt.is_highlighted(): screen.blit(uploadimg, (int(143 / 800. * WIDTH) + int( (665 - 143) / 800. * WIDTH) * 0.55, int(75 - 20 / 600. * HEIGHT) + int( (334 - 70) / 600. * HEIGHT) * 0.3)) screen.blit(delimg, (int(143 / 800. * WIDTH) + int( (665 - 143) / 800. * WIDTH) * 0.20, int(75 / 600. * HEIGHT) + int( (334 - 70) / 600. * HEIGHT) * 0.3)) uploadimgbutt.draw() delimgbutt.draw() if wtf: counter -= 1 if counter == 0: Tk().withdraw() file = tkFileDialog.askopenfilename( initialdir="/Pictures", title="Choose Image To Upload", filetypes=[("image files", ".jpg .png")]) results = [] top_windows = [] win32gui.EnumWindows(windowEnumerationHandler, top_windows) for i in top_windows: if "kaboot" in i[1].lower(): win32gui.ShowWindow(i[0], 5) win32gui.SetForegroundWindow(i[0]) break if file: imaging(screen, file, screen.copy()) previmg = addedimg addedimg = pygame.transform.scale( pygame.image.load("./dependencies/files/temp." + "jpg"), (int((665 - 143) / 800. * WIDTH), int((334 - 75) / 600. * HEIGHT))) regretometer = 3 wtf = False counter = 3 if uploadimgbutt.was_clicked(): wtf = True if idk: counter -= 1 if counter == 0: Tk().withdraw() delimgwindow = tkMessageBox.askyesno( "Remove Image", "Are you sure you want to remove the existing image?\nThis action cannot be reversed!" ) if delimgwindow: addedimg = None quiz['Questions'][QuestioNumber]['photo'] = None quiz['Questions'][QuestioNumber]['image file type'] = None changes = True #print "10" idk = False counter = 3 if delimgbutt.was_clicked() and addedimg: idk = True if regretometer == 3: regretometer = 2 elif regretometer == 2: regretometer = 1 elif regretometer == 1: Tk().withdraw() swich = tkMessageBox.askokcancel( "Preview of New Image", "Are you sure you want to change the image?\nThis action cannot be reversed!" ) if swich: with open("./dependencies/files/temp." + "jpg", 'rb') as img: quiz['Questions'][QuestioNumber][ 'photo'] = base64.b64encode(img.read()) quiz['Questions'][QuestioNumber]['image file type'] = "jpg" changes = True #print "11" else: addedimg = previmg regretometer = 0 if changes: print "updated" with open("dependencies\\quizes\\" + Title + '.json', 'wb') as qfile: json.dump(quiz, qfile, indent=4) changes = False #check_for_place(screen, events) pygame.display.flip() return False