मैं इस ऐप के आकार बदलने की अनुमति देने की कोशिश कर रहा हूं, मैंने RESIZABLE ध्वज रखा है, लेकिन जब मैं आकार बदलने का प्रयास करता हूं, तो यह गड़बड़ हो जाता है! मेरा कोड आज़माएंविंडो का आकार बदलने की अनुमति देना pyGame
यह एक ग्रिड प्रोग्राम है, जब खिड़की का आकार बदलता है, तो मैं ग्रिड को आकार बदलना/हटाना चाहता हूं।
import pygame,math
from pygame.locals import *
# Define some colors
black = ( 0, 0, 0)
white = (255, 255, 255)
green = ( 0, 255, 0)
red = (255, 0, 0)
# This sets the width and height of each grid location
width=50
height=20
size=[500,500]
# This sets the margin between each cell
margin=1
# Initialize pygame
pygame.init()
# Set the height and width of the screen
screen=pygame.display.set_mode(size,RESIZABLE)
# Set title of screen
pygame.display.set_caption("My Game")
#Loop until the user clicks the close button.
done=False
# Used to manage how fast the screen updates
clock=pygame.time.Clock()
# -------- Main Program Loop -----------
while done==False:
for event in pygame.event.get(): # User did something
if event.type == pygame.QUIT: # If user clicked close
done=True # Flag that we are done so we exit this loop
if event.type == pygame.MOUSEBUTTONDOWN:
height+=10
# Set the screen background
screen.fill(black)
# Draw the grid
for row in range(int(math.ceil(size[1]/height))+1):
for column in range(int(math.ceil(size[0]/width))+1):
color = white
pygame.draw.rect(screen,color,[(margin+width)*column+margin,(margin+height)*row+margin,width,height])
# Limit to 20 frames per second
clock.tick(20)
# Go ahead and update the screen with what we've drawn.
pygame.display.flip()
# Be IDLE friendly. If you forget this line, the program will 'hang'
# on exit.
pygame.quit()
कृपया मुझे बताएं कि क्या गलत है, धन्यवाद।
कोड काम करता है, लेकिन तुम सच में पीईपी 8 शैली दिशा निर्देशों को पढ़ना चाहिए। आप 'CreateWindow' जैसे नामों के साथ कई सम्मेलनों का निर्माण कर रहे हैं जो कि कक्षा नहीं है,' हैलो वर्ल्ड 'यह * है, और' DISPLAYSURF' जो निरंतर नहीं है। साथ ही, हर जगह से 'आयात *' स्पैमिंग से बचें, खासकर जब से आप उनका उपयोग नहीं कर रहे हैं (आप वैसे भी सभी 'pygame' कॉल उपसर्ग कर रहे हैं) – MestreLion