Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
PyGame
#1
Hi, so I'm having a bit of trouble exiting the Pygame window I created.
I'm pretty new to python so I assumed this would be an issue Here's the code
import pygame

pygame.init()


screen = pygame.display.set_mode([500, 500])


running = True

while running:

    for event in pygame.event.get():

        if event.type == pygame.QUIT:

            running = False

    screen.fill((255, 255, 255))

    pygame.draw.circle(screen, (0, 0, 255), (250, 250), 75)

    pygame.display.flip()

while 1:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            pygame.display.quit(), sys.exit()
Larz60+ write Dec-08-2020, 08:47 PM:
Please post all code, output and errors (it it's entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.

Fixed for you this time. Please use bbcode tags on future posts.
I also took the liberty to reformat your code
Reply
#2
no = ("no")
rock = ("rock")
paper = ("paper")
scisors = ("scisors")
bad = ("bad")
good = ("good")
yes = ("yes")
name = input("What is your name?")

print("Monika:")
print("Hi again " + name)
print()
print("Monika:")
day = input("How is your day so far (For Purposes of not breaking the system please answer with good or bad")
if day == bad:  print("Oh... Well Hopefully I can cheer you up!")
else: print("Ok")
print ("So, remember the game from yesterday? It was a bit boring right?")
print ("Ehehe It might be a bit better. We'll see!")

game = print("Rock paper scisors shoot!")
answer = input("rock paper or scisors")
print (answer)
if answer == rock: print("paper")
if answer == paper: print("scissors")
if answer == scisors: print("rock")
print ("Oops you lost try again!")
answer = input("rock paper or scisors")
print (answer)
if answer == rock: print("paper")
if answer == paper: print("scisors")
if answer == scisors: print("rock")
print ("Aw not again. Try one more time I know you can do it!")
answer = input("rock paper or scisors")
print (answer)
if answer == rock: print("scisors")
if answer == paper: print("rock")
if answer == scisors: print("paper")
print ("Yay! you won!")
win = input("would you like to play again?")
if win == yes: import rspc
if win == no: print("ok lets continue then")
print("That was fun")
print ("Hey " + name + "?")
print("I have made some changes to my code.")
print("I can now calculate numbers!")
num = int(input("Enter a number!"))
print ("calulating...")
duo1 = num + num
duo2 = num - 2
duo3 = num * num
duo4 = num / 2
print("Hmm.. your numeric number after adding, subtracting multiplying, and dividing is... " + str(duo1) + str(duo2) + str(duo3) + str(duo4))
print ("So, " + name + " I've started to explore and experiment in this new engine... Python was it?. Anyway, I've been trying things and i think i can display something on a screen!")
print ("Let me try...")
import pygame

pygame.init()


# Set up the drawing window

screen = pygame.display.set_mode([500, 500])


# Run until the user asks to quit

running = True

while running:


    # Did the user click the window close button?

    for event in pygame.event.get():

        if event.type == pygame.QUIT:

            running = False


    # Fill the background with white

    screen.fill((255, 255, 255))


    # Draw a solid blue circle in the center

    pygame.draw.circle(screen, (0, 0, 255), (250, 250), 75)


    # Flip the display

    pygame.display.flip()
print ("cool right?")
answer = ("Yes")
answer = input("Yes or no")
if answer == yes: print("I'm glad")
if answer == no: print("Aww")
Here's the output of running the file
Output:
What is your name?d Monika: Hi again d Monika: How is your day so far (For Purposes of not breaking the system please answer with good or badgood Ok So, remember the game from yesterday? It was a bit boring right? Ehehe It might be a bit better. We'll see! Rock paper scisors shoot! rock paper or scisorsrock' rock' Oops you lost try again! rock paper or scisorsrock rock paper Aw not again. Try one more time I know you can do it! rock paper or scisorsrock rock scisors Yay! you won! would you like to play again?no ok lets continue then That was fun Hey d? I have made some changes to my code. I can now calculate numbers! Enter a number!5 calulating... Hmm.. your numeric number after adding, subtracting multiplying, and dividing is... 103252.5 So, d I've started to explore and experiment in this new engine... Python was it?. Anyway, I've been trying things and i think i can display something on a screen! Let me try...
Since I'm using spyder (I don't have administrator privileges so i got anaconda) I got a new error Instead of using techsmart codes like usual
Error:
Traceback (most recent call last): File "C:\Users\kristen.garrett\Downloads\Anaconda\Projects\something.py", line 62, in <module> import pygame ModuleNotFoundError: No module named 'pygame'
Also, Thanks to Larz60+ for helping with formatting my original post!
Reply
#3
That's because you have never quit pygame. Add pygame.quit() at the end of the code.
Reply
#4
(Dec-11-2020, 06:08 PM)MK_CodingSpace Wrote: That's because you have never quit pygame. Add pygame.quit() at the end of the code.
ah alright thanks!
Reply
#5
well, I got a new error or, not really new, but an error none the less it might be because I'm using spyder, or something else. but since I pasted my full code up above, I'll just paste the error
Error:
Traceback (most recent call last): File "C:\Users\kristen.garrett\Downloads\Anaconda\Projects\something.py", line 62, in <module> import pygame ModuleNotFoundError: No module named 'pygame'
I know I stated this in a previous reply but, I really wanted to try and resolve this.
Thanks! Heart Heart
Reply
#6
Doesn't seem you have pygame module installed.
Reply
#7
Oh, how do I do that? As I said before, I'm pretty new so I'm not sure how to do a lot of things yet.
Reply
#8
I have made a short tutorial video on how to install python modules. See if it helps.
Reply
#9
Thanks!
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020