我是第一次使用呼叫分享,搜索结果却没有答案 我想通过共享将参数传递到call中
这是我的密码:
#!/usr/bin/python
import sys,os
import pygame
class Setting():
'''how to deliver self.w and self.h into pic'''
pic = pygame.transform.smoothscale(pygame.image.load("pic.png"),(self.w,self.h)) #how to deliver self.w and self.h in here?
def __init__(self,width,height):
self.w=width
self.h=height
self.flag=pygame.RESIZABLE
self.screen=pygame.display.set_mode((self.w,self.h),self.flag)
self.screen_rect=self.screen.get_rect()
self.bkg=Setting.pic.convert()
pygame.display.set_caption("Muhaha")
def game():
pygame.init()
setting=Setting(1200,800)
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
sys.exit()
setting.screen.blit(setting.bkg,(0,0))
pygame.display.flip()
game()
在创建
class
时,即在game()
函数启动之前,对类级变量进行求值您应该使
pic
成为常规实例成员(即使用self.pic
),或者您应该将它预初始化为None
,并且在第一次调用构造函数时才真正地延迟初始化它相关问题 更多 >
编程相关推荐