【问题标题】:What is this error and how to fix it?.... this scale doesnt work这个错误是什么以及如何解决?....这个秤不工作
【发布时间】:2023-01-24 14:51:36
【问题描述】:

它显示的错误 TypeError: argument 3 must be pygame.Surface, not int

请帮我解决这个问题。 所以该行是导致麻烦的第 15 行和第 21 行......

import pygame
pygame.init()
screen = pygame.display.set_mode((3840,2160))
running = True
mouse = pygame.mouse.get_pos()

pygame.display.set_caption("GermanBall")
bg = pygame.image.load(r"C:\Users\tomarj\OneDrive - Tata Advanced Systems Limited\Desktop\War Crime\Tan.jpg")
icon = pygame.image.load(r"C:\Users\tomarj\OneDrive - Tata Advanced Systems Limited\Desktop\War Crime\box.png")
button1 = pygame.image.load(r"C:\Users\tomarj\OneDrive - Tata Advanced Systems Limited\Desktop\War Crime\shirt.png").convert_alpha()
class Button():
    def __init__(self,x,y,image, scale):
        width = image.get_width()
        height = image.get_height()
        self.image = pygame.transform.scale(image, int(width * scale ), int(height * scale))
        self.rect = self.image.get_rect()
        self.rect.topleft = (x,y)

    def draw(self):
        screen.blit(self.image,(self.rect.x,self.rect.y)) 
start = Button(1200,300,button1,0.5)


pygame.display.set_icon(icon)
while running == True:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            running = False
    screen.blit(bg,(0,0))
    start.draw()
    pygame.display.update()


【问题讨论】:

    标签: python pygame


    【解决方案1】:

    pygame.transform.scale() 的第二个参数是一个包含 2 个元素的元组,用于指定图像的新大小((x, y) 而不是 x, y):

    self.image = pygame.transform.scale(image, int(width * scale ), int(height * scale))

    self.image = pygame.transform.scale(image, (int(width * scale), int(height * scale)))
    

    【讨论】:

      猜你喜欢
      • 2021-06-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-07-02
      • 2021-01-10
      • 1970-01-01
      • 2016-09-19
      • 2015-06-13
      相关资源
      最近更新 更多