Pygame window instantly closing?Update display all at one time PyGameTrying to figure out how to track Pygame events and organize the game's functionsClosing Pygame Window“video system not initialized” While closing pygame windowDraw shape given x and y coordinates pygameRender numpy array on screen in pygamePython and pygame, opening a browser window then detecting when it closes, or other ways to open a browser over a fullscreen pygame GUIpygame image disappears instantlypygame window opens and instantly closespygame window closing instantly? also python.QUIT weird?
How did NASA Langley end up with the first 737?
A burglar's sunglasses, a lady's odyssey
Why is this integration method not valid?
Can you still travel to America on the ESTA waiver program if you have been to Iran in transit?
What were the Ethiopians doing in Xerxes' army?
Are runways booked by airlines to land their planes?
How was Daenerys able to legitimise Gendry?
Can we show a sum of symmetrical cosine values is zero by using roots of unity?
Are there any German nonsense poems (Jabberwocky)?
On San Andreas Speedruns, why do players blow up the Picador in the mission Ryder?
Where is Jon going?
What are nvme namespaces? How do they work?
Why sampling a periodic signal doesn't yield a periodic discrete signal?
Testing using real data of the customer
Finding all files with a given extension whose base name is the name of the parent directory
How to keep consistency across the application architecture as a team grows?
Does French have the English "short i" vowel?
How does the Earth's center produce heat?
Is there an idiom that means that you are in a very strong negotiation position in a negotiation?
Is it legal to have an abortion in another state or abroad?
Why did other houses not demand this?
One word for 'the thing that attracts me'?
Why does splatting create a tuple on the rhs but a list on the lhs?
Why is 'additive' EQ more difficult to use than 'subtractive'?
Pygame window instantly closing?
Update display all at one time PyGameTrying to figure out how to track Pygame events and organize the game's functionsClosing Pygame Window“video system not initialized” While closing pygame windowDraw shape given x and y coordinates pygameRender numpy array on screen in pygamePython and pygame, opening a browser window then detecting when it closes, or other ways to open a browser over a fullscreen pygame GUIpygame image disappears instantlypygame window opens and instantly closespygame window closing instantly? also python.QUIT weird?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
When I try to run this pygame code it instantly closes??
The window doesn't close instantly when I stop drawing text, so I know I must've done something wrong.
import pygame
background_colour = (255, 255, 255)
(width, height) = (1920, 1080)
screen = pygame.display.set_mode((width, height))
pygame.display.set_caption('fat')
screen.fill(background_colour)
font = pygame.font.Font(None, 32)
color = pygame.Color('dodgerblue2')
pygame.display.flip()
running = True
while running:
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
text = ""
while running:
for event in pygame.event.get():
if event.type == pygame.KEYDOWN:
vanishingtext += event.unicode
text += event.unicode
elif event.type == pygame.K_BACKSPACE:
text = text[:-1]
elif event.type == pygame.K_RETURN:
interpret(text)
text = ""
else:
pass
txt_surface = font.render(text, True, color)
screen.blit(txt_surface, (50, 100))
i expect for a screen to appear that allows me to type and backspace, if i press enter the text should completely disappear and a function should run that will interpret the string. i haven't defined interpet as a function yet, but i'm doing it after i've figured out if i can even make it work on a screen.
python-3.x pygame
add a comment |
When I try to run this pygame code it instantly closes??
The window doesn't close instantly when I stop drawing text, so I know I must've done something wrong.
import pygame
background_colour = (255, 255, 255)
(width, height) = (1920, 1080)
screen = pygame.display.set_mode((width, height))
pygame.display.set_caption('fat')
screen.fill(background_colour)
font = pygame.font.Font(None, 32)
color = pygame.Color('dodgerblue2')
pygame.display.flip()
running = True
while running:
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
text = ""
while running:
for event in pygame.event.get():
if event.type == pygame.KEYDOWN:
vanishingtext += event.unicode
text += event.unicode
elif event.type == pygame.K_BACKSPACE:
text = text[:-1]
elif event.type == pygame.K_RETURN:
interpret(text)
text = ""
else:
pass
txt_surface = font.render(text, True, color)
screen.blit(txt_surface, (50, 100))
i expect for a screen to appear that allows me to type and backspace, if i press enter the text should completely disappear and a function should run that will interpret the string. i haven't defined interpet as a function yet, but i'm doing it after i've figured out if i can even make it work on a screen.
python-3.x pygame
Where are you getting the functioninterpret()
from?vanishingtext
is never initialized. Your last two statements seem to be on the wrong level of indentation.
– LuminousNutria
Mar 23 at 23:53
I fixed those now, I erasedinterpret()
andvanishingtext
and fixed the indenting. it still isn't working.
– Winston
Mar 24 at 4:41
add a comment |
When I try to run this pygame code it instantly closes??
The window doesn't close instantly when I stop drawing text, so I know I must've done something wrong.
import pygame
background_colour = (255, 255, 255)
(width, height) = (1920, 1080)
screen = pygame.display.set_mode((width, height))
pygame.display.set_caption('fat')
screen.fill(background_colour)
font = pygame.font.Font(None, 32)
color = pygame.Color('dodgerblue2')
pygame.display.flip()
running = True
while running:
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
text = ""
while running:
for event in pygame.event.get():
if event.type == pygame.KEYDOWN:
vanishingtext += event.unicode
text += event.unicode
elif event.type == pygame.K_BACKSPACE:
text = text[:-1]
elif event.type == pygame.K_RETURN:
interpret(text)
text = ""
else:
pass
txt_surface = font.render(text, True, color)
screen.blit(txt_surface, (50, 100))
i expect for a screen to appear that allows me to type and backspace, if i press enter the text should completely disappear and a function should run that will interpret the string. i haven't defined interpet as a function yet, but i'm doing it after i've figured out if i can even make it work on a screen.
python-3.x pygame
When I try to run this pygame code it instantly closes??
The window doesn't close instantly when I stop drawing text, so I know I must've done something wrong.
import pygame
background_colour = (255, 255, 255)
(width, height) = (1920, 1080)
screen = pygame.display.set_mode((width, height))
pygame.display.set_caption('fat')
screen.fill(background_colour)
font = pygame.font.Font(None, 32)
color = pygame.Color('dodgerblue2')
pygame.display.flip()
running = True
while running:
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
text = ""
while running:
for event in pygame.event.get():
if event.type == pygame.KEYDOWN:
vanishingtext += event.unicode
text += event.unicode
elif event.type == pygame.K_BACKSPACE:
text = text[:-1]
elif event.type == pygame.K_RETURN:
interpret(text)
text = ""
else:
pass
txt_surface = font.render(text, True, color)
screen.blit(txt_surface, (50, 100))
i expect for a screen to appear that allows me to type and backspace, if i press enter the text should completely disappear and a function should run that will interpret the string. i haven't defined interpet as a function yet, but i'm doing it after i've figured out if i can even make it work on a screen.
python-3.x pygame
python-3.x pygame
asked Mar 23 at 23:35
WinstonWinston
213
213
Where are you getting the functioninterpret()
from?vanishingtext
is never initialized. Your last two statements seem to be on the wrong level of indentation.
– LuminousNutria
Mar 23 at 23:53
I fixed those now, I erasedinterpret()
andvanishingtext
and fixed the indenting. it still isn't working.
– Winston
Mar 24 at 4:41
add a comment |
Where are you getting the functioninterpret()
from?vanishingtext
is never initialized. Your last two statements seem to be on the wrong level of indentation.
– LuminousNutria
Mar 23 at 23:53
I fixed those now, I erasedinterpret()
andvanishingtext
and fixed the indenting. it still isn't working.
– Winston
Mar 24 at 4:41
Where are you getting the function
interpret()
from? vanishingtext
is never initialized. Your last two statements seem to be on the wrong level of indentation.– LuminousNutria
Mar 23 at 23:53
Where are you getting the function
interpret()
from? vanishingtext
is never initialized. Your last two statements seem to be on the wrong level of indentation.– LuminousNutria
Mar 23 at 23:53
I fixed those now, I erased
interpret()
and vanishingtext
and fixed the indenting. it still isn't working.– Winston
Mar 24 at 4:41
I fixed those now, I erased
interpret()
and vanishingtext
and fixed the indenting. it still isn't working.– Winston
Mar 24 at 4:41
add a comment |
1 Answer
1
active
oldest
votes
The code is not calling pygame.init()
. Also there's two event loops, the second of which will just drop straight-through once the running
becomes False
.
import pygame
pygame.init()
(width, height) = ( 400, 200)
screen = pygame.display.set_mode((width, height))
pygame.display.set_caption('fat')
background_colour = pygame.Color('white')
color = pygame.Color('dodgerblue2')
font = pygame.font.Font(None, 32)
clock = pygame.time.Clock()
running = True
text = ''
while running:
# handle events and user-input
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
elif event.type == pygame.KEYDOWN:
if ( event.key >= pygame.K_SPACE and event.key <= pygame.K_z ):
# Append key-stroke's character
text += event.unicode
elif ( event.key == pygame.K_BACKSPACE ):
text = text[:-1]
elif ( event.key == pygame.K_RETURN ):
print("interpret(text) - NOT IMPLEMENTED")
text = ""
# repaint the screen
screen.fill(background_colour)
txt_surface = font.render(text, True, color)
screen.blit(txt_surface, (50, 100))
pygame.display.flip()
clock.tick_busy_loop(60) # limit FPS
This code gives me a window titled "fat" with a white background. Typing on an english keyboard gives me blue letters, which can be backspaced. Pressing Enter is somewhat handled.
I tried merging the while loops.while running: for event in pygame.event.get(): if event.type == pygame.QUIT: running = False if event.type == pygame.KEYDOWN: text += event.unicode elif event.type == pygame.K_BACKSPACE: text = text[:-1] elif event.type == pygame.K_RETURN: text = "" else: pass
The window still works but if you know what's wrong could you help? I'm trying to make whatever I type, appear on my screen. It's not working, any ideas why not? The indentation doesn't work in my comment sorry!
– Winston
Mar 26 at 23:20
@Winston - see edit.
– Kingsley
Mar 27 at 1:05
Ik it explicitly says not to say thanks, but I'm going to just say thanks so much. I've just began on python and I'm extremely grateful for the help. Have an incredible day.
– Winston
Mar 27 at 2:56
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55319365%2fpygame-window-instantly-closing%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
The code is not calling pygame.init()
. Also there's two event loops, the second of which will just drop straight-through once the running
becomes False
.
import pygame
pygame.init()
(width, height) = ( 400, 200)
screen = pygame.display.set_mode((width, height))
pygame.display.set_caption('fat')
background_colour = pygame.Color('white')
color = pygame.Color('dodgerblue2')
font = pygame.font.Font(None, 32)
clock = pygame.time.Clock()
running = True
text = ''
while running:
# handle events and user-input
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
elif event.type == pygame.KEYDOWN:
if ( event.key >= pygame.K_SPACE and event.key <= pygame.K_z ):
# Append key-stroke's character
text += event.unicode
elif ( event.key == pygame.K_BACKSPACE ):
text = text[:-1]
elif ( event.key == pygame.K_RETURN ):
print("interpret(text) - NOT IMPLEMENTED")
text = ""
# repaint the screen
screen.fill(background_colour)
txt_surface = font.render(text, True, color)
screen.blit(txt_surface, (50, 100))
pygame.display.flip()
clock.tick_busy_loop(60) # limit FPS
This code gives me a window titled "fat" with a white background. Typing on an english keyboard gives me blue letters, which can be backspaced. Pressing Enter is somewhat handled.
I tried merging the while loops.while running: for event in pygame.event.get(): if event.type == pygame.QUIT: running = False if event.type == pygame.KEYDOWN: text += event.unicode elif event.type == pygame.K_BACKSPACE: text = text[:-1] elif event.type == pygame.K_RETURN: text = "" else: pass
The window still works but if you know what's wrong could you help? I'm trying to make whatever I type, appear on my screen. It's not working, any ideas why not? The indentation doesn't work in my comment sorry!
– Winston
Mar 26 at 23:20
@Winston - see edit.
– Kingsley
Mar 27 at 1:05
Ik it explicitly says not to say thanks, but I'm going to just say thanks so much. I've just began on python and I'm extremely grateful for the help. Have an incredible day.
– Winston
Mar 27 at 2:56
add a comment |
The code is not calling pygame.init()
. Also there's two event loops, the second of which will just drop straight-through once the running
becomes False
.
import pygame
pygame.init()
(width, height) = ( 400, 200)
screen = pygame.display.set_mode((width, height))
pygame.display.set_caption('fat')
background_colour = pygame.Color('white')
color = pygame.Color('dodgerblue2')
font = pygame.font.Font(None, 32)
clock = pygame.time.Clock()
running = True
text = ''
while running:
# handle events and user-input
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
elif event.type == pygame.KEYDOWN:
if ( event.key >= pygame.K_SPACE and event.key <= pygame.K_z ):
# Append key-stroke's character
text += event.unicode
elif ( event.key == pygame.K_BACKSPACE ):
text = text[:-1]
elif ( event.key == pygame.K_RETURN ):
print("interpret(text) - NOT IMPLEMENTED")
text = ""
# repaint the screen
screen.fill(background_colour)
txt_surface = font.render(text, True, color)
screen.blit(txt_surface, (50, 100))
pygame.display.flip()
clock.tick_busy_loop(60) # limit FPS
This code gives me a window titled "fat" with a white background. Typing on an english keyboard gives me blue letters, which can be backspaced. Pressing Enter is somewhat handled.
I tried merging the while loops.while running: for event in pygame.event.get(): if event.type == pygame.QUIT: running = False if event.type == pygame.KEYDOWN: text += event.unicode elif event.type == pygame.K_BACKSPACE: text = text[:-1] elif event.type == pygame.K_RETURN: text = "" else: pass
The window still works but if you know what's wrong could you help? I'm trying to make whatever I type, appear on my screen. It's not working, any ideas why not? The indentation doesn't work in my comment sorry!
– Winston
Mar 26 at 23:20
@Winston - see edit.
– Kingsley
Mar 27 at 1:05
Ik it explicitly says not to say thanks, but I'm going to just say thanks so much. I've just began on python and I'm extremely grateful for the help. Have an incredible day.
– Winston
Mar 27 at 2:56
add a comment |
The code is not calling pygame.init()
. Also there's two event loops, the second of which will just drop straight-through once the running
becomes False
.
import pygame
pygame.init()
(width, height) = ( 400, 200)
screen = pygame.display.set_mode((width, height))
pygame.display.set_caption('fat')
background_colour = pygame.Color('white')
color = pygame.Color('dodgerblue2')
font = pygame.font.Font(None, 32)
clock = pygame.time.Clock()
running = True
text = ''
while running:
# handle events and user-input
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
elif event.type == pygame.KEYDOWN:
if ( event.key >= pygame.K_SPACE and event.key <= pygame.K_z ):
# Append key-stroke's character
text += event.unicode
elif ( event.key == pygame.K_BACKSPACE ):
text = text[:-1]
elif ( event.key == pygame.K_RETURN ):
print("interpret(text) - NOT IMPLEMENTED")
text = ""
# repaint the screen
screen.fill(background_colour)
txt_surface = font.render(text, True, color)
screen.blit(txt_surface, (50, 100))
pygame.display.flip()
clock.tick_busy_loop(60) # limit FPS
This code gives me a window titled "fat" with a white background. Typing on an english keyboard gives me blue letters, which can be backspaced. Pressing Enter is somewhat handled.
The code is not calling pygame.init()
. Also there's two event loops, the second of which will just drop straight-through once the running
becomes False
.
import pygame
pygame.init()
(width, height) = ( 400, 200)
screen = pygame.display.set_mode((width, height))
pygame.display.set_caption('fat')
background_colour = pygame.Color('white')
color = pygame.Color('dodgerblue2')
font = pygame.font.Font(None, 32)
clock = pygame.time.Clock()
running = True
text = ''
while running:
# handle events and user-input
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
elif event.type == pygame.KEYDOWN:
if ( event.key >= pygame.K_SPACE and event.key <= pygame.K_z ):
# Append key-stroke's character
text += event.unicode
elif ( event.key == pygame.K_BACKSPACE ):
text = text[:-1]
elif ( event.key == pygame.K_RETURN ):
print("interpret(text) - NOT IMPLEMENTED")
text = ""
# repaint the screen
screen.fill(background_colour)
txt_surface = font.render(text, True, color)
screen.blit(txt_surface, (50, 100))
pygame.display.flip()
clock.tick_busy_loop(60) # limit FPS
This code gives me a window titled "fat" with a white background. Typing on an english keyboard gives me blue letters, which can be backspaced. Pressing Enter is somewhat handled.
edited Mar 27 at 1:07
answered Mar 25 at 0:16
KingsleyKingsley
4,02641431
4,02641431
I tried merging the while loops.while running: for event in pygame.event.get(): if event.type == pygame.QUIT: running = False if event.type == pygame.KEYDOWN: text += event.unicode elif event.type == pygame.K_BACKSPACE: text = text[:-1] elif event.type == pygame.K_RETURN: text = "" else: pass
The window still works but if you know what's wrong could you help? I'm trying to make whatever I type, appear on my screen. It's not working, any ideas why not? The indentation doesn't work in my comment sorry!
– Winston
Mar 26 at 23:20
@Winston - see edit.
– Kingsley
Mar 27 at 1:05
Ik it explicitly says not to say thanks, but I'm going to just say thanks so much. I've just began on python and I'm extremely grateful for the help. Have an incredible day.
– Winston
Mar 27 at 2:56
add a comment |
I tried merging the while loops.while running: for event in pygame.event.get(): if event.type == pygame.QUIT: running = False if event.type == pygame.KEYDOWN: text += event.unicode elif event.type == pygame.K_BACKSPACE: text = text[:-1] elif event.type == pygame.K_RETURN: text = "" else: pass
The window still works but if you know what's wrong could you help? I'm trying to make whatever I type, appear on my screen. It's not working, any ideas why not? The indentation doesn't work in my comment sorry!
– Winston
Mar 26 at 23:20
@Winston - see edit.
– Kingsley
Mar 27 at 1:05
Ik it explicitly says not to say thanks, but I'm going to just say thanks so much. I've just began on python and I'm extremely grateful for the help. Have an incredible day.
– Winston
Mar 27 at 2:56
I tried merging the while loops.
while running: for event in pygame.event.get(): if event.type == pygame.QUIT: running = False if event.type == pygame.KEYDOWN: text += event.unicode elif event.type == pygame.K_BACKSPACE: text = text[:-1] elif event.type == pygame.K_RETURN: text = "" else: pass
The window still works but if you know what's wrong could you help? I'm trying to make whatever I type, appear on my screen. It's not working, any ideas why not? The indentation doesn't work in my comment sorry!– Winston
Mar 26 at 23:20
I tried merging the while loops.
while running: for event in pygame.event.get(): if event.type == pygame.QUIT: running = False if event.type == pygame.KEYDOWN: text += event.unicode elif event.type == pygame.K_BACKSPACE: text = text[:-1] elif event.type == pygame.K_RETURN: text = "" else: pass
The window still works but if you know what's wrong could you help? I'm trying to make whatever I type, appear on my screen. It's not working, any ideas why not? The indentation doesn't work in my comment sorry!– Winston
Mar 26 at 23:20
@Winston - see edit.
– Kingsley
Mar 27 at 1:05
@Winston - see edit.
– Kingsley
Mar 27 at 1:05
Ik it explicitly says not to say thanks, but I'm going to just say thanks so much. I've just began on python and I'm extremely grateful for the help. Have an incredible day.
– Winston
Mar 27 at 2:56
Ik it explicitly says not to say thanks, but I'm going to just say thanks so much. I've just began on python and I'm extremely grateful for the help. Have an incredible day.
– Winston
Mar 27 at 2:56
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55319365%2fpygame-window-instantly-closing%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Where are you getting the function
interpret()
from?vanishingtext
is never initialized. Your last two statements seem to be on the wrong level of indentation.– LuminousNutria
Mar 23 at 23:53
I fixed those now, I erased
interpret()
andvanishingtext
and fixed the indenting. it still isn't working.– Winston
Mar 24 at 4:41