This is my first post and I am new to python (so please go easy on me
I have just recieved SenseHAT for my birthday and I am busy playing with it and I have created a scrolling text countdown timer that will count down the days to any given event. The event and date are set via user input so they write the event and give the date of the event and the code will display the event and number of days until it.
I want to include the ability for the user to select the text colour and background colour of the scrolling text, but I am stuck with the code.
This is my current code:
Code: Select all
from sense_hat import SenseHat
import datetime
import time
from datetime import timedelta
sense = SenseHat()
Red =(255, 0, 0)
Orange = (255, 128, 0)
Yellow = (255, 255, 0)
Green = (0, 255, 0)
Blue = (0, 0, 255)
Purple =(255, 0, 255)
event = input("Enter an event: ")
def ObtainDate():
while True:
userIn = input("Type Date: dd/mm/yy: ")
try:
return datetime.datetime.strptime(userIn, "%d/%m/%y")
except ValueError:
print ("Invalid Format!\n")
t1 = ObtainDate()
colour = input("Choose a text colour: Enter Red, Orange, Yellow, Green, Blue, Purple: ")
#First message
while True:
text = event + ' = ' #String to be displayed on the first round of text
sense.show_message(text, scroll_speed=0.05, text_colour = colour)
time.sleep(0.1)
#Second message
currentDay = datetime.datetime.today()
difference = (t1 - currentDay).days
display_text = str(difference)
sense.show_message(display_text + "days", scroll_speed = 0.05, text_colour = colour, back_colour = (0,0,255)) This work in that the user can type an event and give a day, but then it fails.
In my limited understanding it is because in the following line: sense.show_message(text, scroll_speed=0.05, text_colour = colour) have text_colour set to colour (the user input variable) is not allowed.
I am unsure of how to rectify this. If someone could help me out that would be great.