by CodeChum Admin
I got my grandmother a new phone because I thought that we could talk more everyday by texting. Well, let’s just say that my grandma’s eyes aren’t the best anymore so she can’t really see what I text her and because of that she wants to ditch texting and stick with carrier pigeons. You know how embarrassing it is for a kid like me to be seen using carrier pigeons?!?! Well, anyway, I was hoping that you could make a program that takes my text and make it bigger, a LOT bigger. How about you test it out by only using the letters A, B, and C first.
Input
1. My text
Description
This is a string with characters A, B, and C.
Constraints
It is guaranteed that all letters are in uppercase.
Output
The first line will contain a message prompt to input my text.
The succeeding lines will contain the enlarged text.
SOLUTION TO THE ABOVE QUESTION
In this question we will use the pygame package. A user will enter a string and the enlarged text will be displayed in a pygame window.
SOLUTION CODE
import pygame
from pygame.locals import *
pygame.init()
pygame.font.init()
# font object..................................
def create_font(t,s=72,c=(255,255,0), b=False,i=False):
font = pygame.font.SysFont("Arial", s, bold=b, italic=i)
text = font.render(t, True, c)
return text
# Text to be rendered with create_font
my_string = input("Enter your String: ")
game_over = create_font(my_string)
SURF = pygame.display.set_mode((600, 400))
loop = True
clock = pygame.time.Clock()
while loop == True:
SURF.fill((0,0,0))
x, y = pygame.mouse.get_pos()
SURF.blit(game_over, (100,150))
for e in pygame.event.get():
if e.type == QUIT:
loop = 0
pygame.display.update()
clock.tick(60)
pygame.quit()
SAMPLE PROGRAM OUTPUT
Comments
Leave a comment