[英]calling functions python (pygame)
我想擁有大量的功能,當我在屏幕上調用每個功能時,它會在屏幕上顯示我想要的東西。 我在這個簡單的程序上遇到了麻煩。 我想在屏幕上顯示文字。 但它所做的只是顯示屏幕。
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"))
這是發生的情況(如果我做對了):
希望能有所幫助;)
乍一看,我相信您會兩次調用屏幕功能,從而創建兩個屏幕。
函數“名稱”創建帶有標簽的屏幕。 在調用“屏幕”函數之前,在代碼的最后一行中調用此函數。
最終在最后一行中再次調用“屏幕”功能時,這將創建一個沒有標簽的新屏幕。
同樣,函數“屏幕”不使用為函數指定的參數“名稱”。 如果您想設置屏幕的標題,那么我想參考http://www.pygame.org/docs/ref/display.html#pygame.display.set_caption
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.