【问题标题】:Why can´t i use a pre-defined variable for the pygame rect function? [duplicate]为什么我不能为 pygame rect 函数使用预定义变量? [复制]
【发布时间】:2019-07-17 12:29:53
【问题描述】:

谁能解释为什么这不起作用? 有没有办法让这个工作,或者只是不可能给 pygame rect 函数一个带有所需参数的预定义变量?

import pygame

pygame.init()

win = pygame.display.set_mode((1200, 600))
blue = (0, 0, 255)

x = (win, blue, (0, 510, 1200, 190))

pygame.draw.rect(x)

每次我尝试代码时,它都会说rect 函数至少需要 3 个参数。

【问题讨论】:

  • 解压pygame.draw.rect(*x)

标签: python pygame


【解决方案1】:

要使用来自 x 的三个参数调用 rect,而不是恰好由 3 个东西组成的一个参数,您可以这样做:

pygame.rect( *x )

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-11-09
    • 1970-01-01
    • 2016-03-08
    • 1970-01-01
    • 2022-01-26
    • 2021-03-30
    • 2020-05-11
    相关资源
    最近更新 更多