I'm trying to create a GUI that displays some buttons when you click a button. However, I cannot figure out how to detect if you click the nested button. Here's my code:
import pygame
from pygame.locals import *
import sys
import os
import time
from random import randrange, randint
import base64
from configparser import ConfigParser
import tkinter
from tkinter import Tk, messagebox, simpledialog
configure = ConfigParser()
configure.read('dooroperatingsystempassword.txt')
start_time = time.time()
WIDTH = 801
HEIGHT = 452
CENTER_X = WIDTH / 2
CENTER_Y = HEIGHT / 2
admin = False
complete = False
failed = False
loading = False
first_time_password = True
back_button_dofalsetotrue = 'none'
back_button_dotruetofalse = 'none'
start_screen = True
system_screen = False
privacy_screen = False
account_screen = False
time_button_screen = False
keyboard_screen = False
shutdown_screen = False
system = pygame.image.load(r'images\system_button.png')
privacy = pygame.image.load(r'images\security_button.png')
background = pygame.image.load(r'images\background.png')
shutdown = pygame.image.load(r'images\shutdown.png')
doors_icon = pygame.image.load(r'images\doors2_icon.png')
pygame.init()
clock = pygame.time.Clock()
screen = pygame.display.set_mode((WIDTH, HEIGHT))
pygame.mouse.set_visible(1)
pygame.display.set_caption('Doors Operating System (DOS)')
pygame.display.set_icon(doors_icon)
root = Tk()
root.withdraw()
shutdown_img_for_tkinter = tkinter.PhotoImage(file=r'images\shutdown.png')
root.iconphoto(False, shutdown_img_for_tkinter)
def letters_off():
global loading
if loading:
loading = False
def decode(decode_message):
base64_bytes = decode_message.encode('ascii').decode('UTF-8')
message = base64.b64decode(base64_bytes).decode('UTF-8')
return message
def check_mouse_pos(pos):
global start_screen, loading_first_time_password
global system_screen, privacy_screen, account_screen, time_button_screen, keyboard_screen, shutdown_screen
print(pos)
if start_screen and pos[0] >= 145 and pos[0] <= 233 and pos[1] >= 85 and pos[1] <= 167:
password2 = simpledialog.askstring('Welcome to Systems', 'Password?')
paswrd2 = configure.get('password section 2', 'password2')
paswrd2 = paswrd2.rstrip()
paswrd2 = decode(paswrd2)
if password2 == paswrd2:
start_screen = False
system_screen = True
print('sfdfsfsdfsfsdfsf')
#while not start_screen and system_screen:
# if pos[0] >= 315 and pos[0] <= 403 and pos[1] >= 85 and pos[1] <= 167:
# print('es')
while not failed:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
sys.exit()
elif event.type == pygame.MOUSEBUTTONDOWN:
position = pygame.mouse.get_pos()
if start_screen:
check_mouse_pos(position)
screen.blit(background, (0, 0))
if first_time_password:
screen.blit(background, (0, 0))
pygame.display.update()
password1 = simpledialog.askstring('Welcome to Doors Operating System', 'Password?')
paswrd1 = configure.get('password section 1', 'password1')
paswrd1 = paswrd1.rstrip()
paswrd1 = decode(paswrd1)
if password1 == paswrd1:
print('yay dun')
first_time_password = False
if not complete:
if start_screen and not system_screen:
screen.blit(system, (145, 85))
elif not start_screen and system_screen:
screen.blit(shutdown, (315, 85))
else:
messagebox.showinfo('Error 001', 'LOL NOOB YOU FAILED ROFL LOL NOOB HAHA LOOK AT YOUR FACE IT LOOKS LIKE DEATH ROFL LOL')
pygame.quit()
sys.exit()
else:
if not complete:
if start_screen and not system_screen:
screen.blit(system, (145, 85))
elif not start_screen and system_screen:
screen.blit(shutdown, (315, 85))
pygame.display.flip()
pygame.display.update()
First, I load my images, which work fine. Next, I defined a function decode that decodes my base 64 encoded passwords. Then, I define a function check_mouse_pos that actually checks if the mouse has clicked on the image. Finally, I made a while loop that detects if I clicked my mouse.
I'm pretty new in Pygame, so this question my seem trivial :(