You have to implement the VIDEORESIZE
event (see pygame.event
).
When the window is resized, then get the new size of the window from the even attributes:
width, height = event.w, event.h
Create a new Surface associated to the window and scale the background to the new size:
def screen_setting(width,height):
p.init()
flag = p.RESIZABLE
screen=p.display.set_mode((width, height), flag, 0)
bk_orig = p.image.load(pic).convert()
bk = p.transform.smoothscale(bk_orig, (width, height))
while True:
for event in p.event.get():
if event.type == p.QUIT:
sys.exit()
elif event.type == p.VIDEORESIZE:
width, height = event.w, event.h
screen = p.display.set_mode((width, height), flag, 0)
bk = p.transform.smoothscale(bk_orig, (width, height))
screen.blit(bk, (0 ,0))
p.display.flip()
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…