调用函数 python (pygame) [英] calling functions python (pygame)

查看:61
本文介绍了调用函数 python (pygame)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要加载大量函数,当我调用屏幕函数上的每个函数时,它会在屏幕上显示我想要的东西.我在这个简单的程序上遇到了麻烦.我想在写入时在屏幕上显示文本.但它所做的只是显示屏幕.

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"))

推荐答案

这是会发生的(如果我做对了):

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

  • 将 name("donkey from shrek") 的结果传递给 screen() [第 18 行]
    • name() 被调用 [line 18]
      • 名称:创建标签 [第 14 行]
      • 名称:调用屏幕 [第 15 行]
      • screen:创建新的显示并返回它[第 6-9 行]
      • 名称:返回显示的 blit 标签 [第 15 行]
      • 返回blitted"显示[第 16 行]
      • screen:不关心name"中的显示对象[第 6-9 行]
      • screen:创建并返回一个空白显示[第 6-9 行]

      希望有帮助;)

      这篇关于调用函数 python (pygame)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆