Jump to content
  • Advertisement
Sign in to follow this  
monp

Basic Pygame Help.

This topic is 3791 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello, i am having trouble pulling up a blank window using the following code from a tutorial i have been reading. import sys, os import pygame from pygame.locals import * if not pygame.font: print 'Fonts are Disabled' if not pygame.mixer: print 'Sounds are Disabled' class pypacMain: def __init__ (self,width=640,height=480): pygame.init() self.width = width self.height = height self.screen = pygame.diplay.set_mode((self.width, self.height)) def MainLoop(self): while 1: for event in pygame.event.get(): if event.type == pygame.QUIT: sys.exit() if __name__ == "__main__": MainWindow = pypacMain() MainWindow.MainLoop() At this part of the tutorial it says it would just bring up a blank window, but whenever i run it, it does nothing. I have brought up a blank window in alot easier fashion but am wondering why this one doesn't work.

Share this post


Link to post
Share on other sites
Advertisement
I'm not sure. Maybe you misspelled 'display' in pygame.display.set_mode(). Fixing that works for me.

If you ask me, this code is ridiculously overcomplex for what it does.

To make a window, all you really need is:
import pygame
pygame.display.set_mode((800,600))
Here's a smaller tutorial that also includes a basic drawing function:
import pygame
import sys
from pygame.locals import * #Import stuff for event handling, other modules, etc.
pygame.init() #initialize pygame. You must do this before doing a lot of Pygame stuff.
Surface = pygame.display.set_mode((800,600)) #Make the actual window
def GetInput():
keystate = pygame.key.get_pressed() #Get the position of all the keys
for event in pygame.event.get():
if event.type == QUIT or keystate[K_ESCAPE]: #QUIT is the 'X' on the window, keystate[K_ESCAPE] is True when the ESCAPE key is pressed.
pygame.quit(); sys.exit() #Quit Pygame, quit the program.
def Draw():
Surface.fill((255,255,255)) #Fill the screen with white. (One never really erases anything, one just draws over it).
pygame.display.flip() #Draw the Screen in the Window.
def main():
while True: #Main Loop
GetInput()
Draw()
if __name__ == '__main__': main() #Start the Main Function.
BTW, you'll need indentations. I'm not sure if you didn't know or inadvertently omitted them in posting.
G

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!