Reputation: 440
I just wrote some code that works in the commandline, so now I'd like to give it some graphics. Now, this is my very first programming project so bear with me as I try to explain the problem:
I'm using PyGame and initialised the window as follows:
import pygame, pygame.midi,pygame.font, random
(width, height) = (600, 400)
background = (220,220,220)
pygame.midi.init()
pygame.font.init()
screen = pygame.display.set_mode((width, height))
pygame.display.set_caption("Chord trainer")
screen.fill(background)
pygame.display.flip()
Then I attempt to render text (which does not give any errors):
myfont = pygame.font.SysFont("Arial", 80)
letter = myfont.render("SOME WEIRD TEST TO TRY AND GET THINGS WORKING",0,(0,0,0))
screen.blit(letter,(100,100))
And because I'd like to actually see my text before the program closes, I set up an infinite loop:
running = True
while running:
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
When I run it, I just get the grey screen I wanted, but without any sort of text, which would make me think that there's something wrong with my blit command, but I can't figure out what.
Initially I had the rendering set in a loop, but that just made the program unresponsive so I took is out for debugging. For completeness, here is that loop:
while True:
# Decide on random chord
c1 = random.choice(chords)
# Make sure that no repitition takes place.
if c1==c2:
while c1==c2:
c1=random.choice(chords)
c2 = c1
myfont = pygame.font.SysFont("Arial", 80)
letter = myfont.render(str(c1),0,(0,0,0))
screen.blit(letter,(100,100))
# Listen to Midi device and search for c.
midi_listen(inp,sorted(c1))
score += 1
Upvotes: 1
Views: 3192
Reputation: 56
You need to add
pygame.display.flip()
after
letter = myfont.render("SOME WEIRD TEST TO TRY AND GET THINGS WORKING",0,(0,0,0))
screen.blit(letter,(100,100)
It will update your screen and normally you will be able to see your text.
Upvotes: 4