0

I am tying to have a load of functions where by when i call each function on the screen function, it displays stuff i want on the screen. Im having trouble with this simple program. I would like to display text on the screen when i write to it. but all its doing is displaying the screen.

import pygame
from pygame.locals import *

pygame.init()

def screen(width,height,name):
    screen = pygame.display.set_mode((600,600))
    screen=pygame.display.set_mode((width,height))
    return screen

def name(name=""):
    pygame.font.init()
    myfont = pygame.font.SysFont("monospace", 15)
    label = myfont.render("Some text!", 1, (255,255,0))
    result=screen(640,480,name).blit(label, (100, 100))
    return result

screen(640,480,name("donkey from shrek"))

2 Answers 2

1

this is what happens (if I get it right):

  • pass the result of name("donkey from shrek") to screen() [line 18]
    • name() gets called [line 18]
      • name: creates label [line 14]
      • name: calls screen [line 15]
      • screen: create new display and return it [line 6-9]
      • name: blit label to returned display [line 15]
      • return the "blitted" display [line 16]
  • the blitted display gets passed to screen() [line 18]
    • screen: doesn't care about the display object in "name" [line 6-9]
    • screen: creates and returns a blank display [line 6-9]

Hope that helps ;)

Sign up to request clarification or add additional context in comments.

4 Comments

wait i dont understand this logic, could you convert to pseudo? Since i have started programming, i have lost the ability to read English, i read code ;)
Well that's the logic you have written :) No need for pseudo code, it would look the same ;) Will try and Edit line numbers The whole issue is that your name() call is useless as in the end screen() creates a 2nd blank screen as user2728470 mentioned
If you call name() in line 18 (instead of screen()) it should work. However the code would need some refactoring as it looks very confusing :)
okay, i forgot to call update method, thanks for your help:) x
0

On first glance, i believe you are calling the screen function twice, and thus creating two screens.

The function "name" creates a screen with a label. This function is called in the last line of your code, before the "screen" function is called.

When eventually the "screen" function is called (again) in the last line, this will create a new screen, without label... .

Also the function "screen" does not utilize the argument "name" that is given to the function. If you want to set the caption of the screen, then i would like to refer to http://www.pygame.org/docs/ref/display.html#pygame.display.set_caption

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.