Unofficial Raspberry Pi Clock Application

Hi guys. Today I have been experimenting with Python and Pygame. I managed to make a clock application for the Raspberry Pi.

Here is the code:

import pygame, sys, time

pygame.init()

screen = pygame.display.set_mode((1184, 624),
pygame.FULLSCREEN)
pygame.display.set_caption(“Raspberry Pi Clock”)

clockFont = pygame.font.Font(None, 72)
clock = pygame.time.Clock()

##COLOURS

WHITE = (255, 255, 255)
RED = (255, 0, 0)

##IMAGES
logo = pygame.image.load(“/usr/share/raspberrypi-artwork/launch.png”)
piclock = pygame.image.load(“raspitimebackground.png”)

##CODE
screen.blit(piclock, (0, 0))
pygame.display.flip()

time.sleep(2)

screen.blit(logo, (0, 0))
pygame.display.flip()

theFont = pygame.font.Font(None, 32)
theSurf = theFont.render(“Raspberry Pi”, True, WHITE)
theRect = theSurf.get_rect()
theRect.midtop = (115, 5)
screen.blit(theSurf, theRect)
pygame.display.flip()

loadFont = pygame.font.Font(None, 32)
loadSurf = theFont.render(“Press Enter to load the desktop”, True, WHITE)
loadRect = theSurf.get_rect()
loadRect.midtop = (500, 300)
screen.blit(loadSurf, loadRect)
pygame.display.flip()
while True:
clock.tick(1)
clockTime = time.strftime(“%H:%M:%S”, time.localtime())
clockText = clockFont.render(str(clockTime), True, WHITE, RED)
screen.blit(clockText, (1000, 550))
pygame.display.update()
for event in pygame.event.get():
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_RETURN:
pygame.quit()
sys.exit()

The following image is required for this project file

raspitimebackground

If for some reason you ever need this image, feel free to use it. Learn more.

In the future, I will make a blog post about auto starting apps on the Pi.

Enjoy!

Epic Chas Gamer 😀

 

Advertisements

About Epic Chas Gamer

I am a computer programmer who can create a mobile app for your website. I am also a Raspberry Pi expert and modern gamer, with Minecraft as my favourite. I develop ECG SeaSurf, a web browser only just released, crafting the future. The project is available for Windows and a BETA Linux version at coolchasgamer.wordpress.com/ecg-seasurf-unstable. I will also be voicing Shield Evil in "ECG Sir Wolf's Castle", as well as Chas and a few others. UPDATED ON 12th February 2017, at 14:46
This entry was posted in How to use a Raspberry Pi, Project Files, Python, Raspberry Pi, Raspberry Pi 3 and tagged , . Bookmark the permalink.

Go on, you know you want to! Leave a comment

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s