0

So basically what happened is, I am making a reminder app where it rings an alarm at a certain time, the problem is I'm having trouble displaying a time. I've used show text in this code to display the current time, but when I try to display an activity I'm not getting an error but it's not showing. Code:

from pygame import mixer
from datetime import datetime
import pygame
from pygame.locals import *
pygame.init()
mixer.init()
screen = pygame.display.set_mode((500,500))
pygame.display.set_caption("App")
mixer.music.load("song.mp3")
mixer.music.set_volume(0.7)
global o
o=0
#FUNCTIONS
def show_text(msg, x, y, color, size):
    fontobj= pygame.font.SysFont("freesans", size)
    msgobj = fontobj.render(msg,False,color)
    screen.blit(msgobj,(x, y))
def Session():
    session_name = input("What do you want to call your session?")
    starttime = input("What time do you want to start? (Example 600 = 6:00)")
    endtime = input("What time do you want to end? (Example 700 = 7:00)")
    o=1
    
    pygame.display.update()
    
    
    
    
#VARIABLES
green = (0,255,0)
black = (0,0,0)
white = (255,255,255)
activites = ""
start_time = ""
end_time = ""
counter = 0
hours = 60
#END OF VARIABLES
while True:
    
    for event in pygame.event.get():
        if event.type == QUIT:
            pygame.quit()
            exit()
        if event.type == MOUSEBUTTONDOWN:
            x, y = pygame.mouse.get_pos()
            
            if x>239 and x<286 and y> 399 and y<446:
                counter = 1
            if counter == 1:
               Session()
        
               counter = 0
    screen.fill(black)
            
                
    #GETTING TIME
    now = datetime.now()
    current_time = now.strftime("%H:%M:%S")
    #END OF GETTING TIME

    #GUI
    
    show_text(str(current_time),220,10,green,20)
    if o==1:
        show_text(str(session_name), 180,200, white, 75)
        
    show_text("Add Activity",220,375,green,20)
    pygame.draw.rect(screen,green,(240,400,45,45))
    pygame.draw.rect(screen,white,(260,403,5,40))
    pygame.draw.rect(screen,white,(245,420,37,5))
    
    #END OF GUI
    
    pygame.display.update()

I Would appreciate a response on why it was wrong as well as a fixed code, thanks in advance!

qouify
  • 3,698
  • 2
  • 15
  • 26
Ravishankar D
  • 131
  • 10
  • *"when I try to display an activity I'm not getting an error but it's not showing."* - Where in your code do you try to show an activity? What is the problem? – Rabbid76 Mar 06 '22 at 07:42
  • 1
    You cannot use `input` in the application loop. See [Why is my display not responding while waiting for input?](https://stackoverflow.com/questions/67111782/why-is-my-display-not-responding-while-waiting-for-input/67113040#67113040) and [How to create a text input box with pygame?](https://stackoverflow.com/questions/46390231/how-to-create-a-text-input-box-with-pygame/64613666#64613666). – Rabbid76 Mar 06 '22 at 07:44

0 Answers0