Pygame Tutorial #1 - Basic Movement and Key Presses

Поділитися
Вставка
  • Опубліковано 6 лис 2017
  • This is a new series on my channel where I am going to be going through the pygame module in python. Pygame is used to make games and is also useful for making software and other types of programs. In this first tutorial I show how to set up the screen and implement basic character movement.
    ⭐ Kite is a free AI-powered coding assistant for Python that will help you code smarter and faster. Integrates with Atom, PyCharm, VS Code, Sublime, Vim, and Spyder. I've been using Kite for 6 months and I love it! kite.com/download/?...
    Want to learn the fundamentals of programming? Check out my course:
    tech-with-tim.teachable.com/p...
    Please LIKE and SUBSCRIBE for more content!
    Check out My Website: techwithtim.net
    SOURCE CODE: techwithtim.net/tutorials/gam...
    How To Install Pygame: • Video
    Python Programming Tutorials: • Python Programming Tut...
    ◾◾◾◾◾
    💻 Enroll in The Fundamentals of Programming w/ Python
    tech-with-tim.teachable.com/p...
    📸 Instagram: / tech_with_tim
    🌎 Website techwithtim.net
    📱 Twitter: / techwithtimm
    ⭐ Discord: / discord
    📝 LinkedIn: / tim-rusci. .
    📂 GitHub: github.com/techwithtim
    🔊 Podcast: anchor.fm/tech-with-tim
    💵 One-Time Donations: www.paypal.com/donate/?token=...
    💰 Patreon: / techwithtim
    ◾◾◾◾◾◾
    ⚡ Please leave a LIKE and SUBSCRIBE for more content! ⚡

КОМЕНТАРІ • 1,2 тис.

  • @TechWithTim
    @TechWithTim  5 років тому +94

    Interested in what its like to be a computer science student? Check out my Podcast: anchor.fm/tech-with-tim
    Follow me on Twitter: twitter.com/TechWithTimm
    Join my Discord to Ask Questions and get help with pygame! discord.gg/pr2k55t
    SOURCE CODE: techwithtim.net/tutorials/game-development-with-python/pygame-tutorial/

    • @ashura4841
      @ashura4841 5 років тому

      why do i get "invalid syntax"

    • @TechWithTim
      @TechWithTim  5 років тому +15

      If I had to guess you probably have...
      Invalid syntax
      You typed something wrong, spelt something wrong, forgot a bracket, messed up indent...

    • @multi8108
      @multi8108 5 років тому

      i am

    • @devindakekulawela6907
      @devindakekulawela6907 5 років тому

      my keys aren't moving

    • @ganeshinysridharan4323
      @ganeshinysridharan4323 5 років тому

      I'm getting an error "source code string cannot contain null bytes"...I had this working the first time, but then when I tried it on my own the 2nd time,I got this error message...please help mee...

  • @BEHDJDHDGAFAJFKNFH
    @BEHDJDHDGAFAJFKNFH 3 роки тому +128

    while True:
    print('thanks')

  • @tenmamut
    @tenmamut 5 років тому +21

    Very nice of you to include a challenge with a solution hint at the end, very educational, feels like I'm in school again.

    • @asishraz6173
      @asishraz6173 3 роки тому

      Anyone wants to learn Python through basic came can see this link:
      ua-cam.com/video/ijOGhZFeVGA/v-deo.html
      And let me know, whether you liked it or not

  • @c0nn0rr0che2
    @c0nn0rr0che2 3 роки тому +58

    This is the first time where with my beginner level python knowledge helped me understand something like this. Great Video!

  • @viennesekangaroo
    @viennesekangaroo 4 роки тому +16

    Seriously the best tutorial I've ever seen. Good job!

  • @mrknarf4438
    @mrknarf4438 4 роки тому +8

    Thanks a lot, just what I was looking for: short, clear and practical. Let's go to the next one! 😀

  • @hapdio4331
    @hapdio4331 4 роки тому +7

    Never seen a better tutorial. This is great, thank you so much!

  • @metepure
    @metepure 3 роки тому

    I swear Tim, you are the king of python, no channel taught me until you did. RESPECT.

  • @DearHRS
    @DearHRS 3 роки тому +14

    Dude, this is awesome, I am so proud of myself making a drawing rectangle

  • @arnavjabulee3588
    @arnavjabulee3588 6 років тому +28

    This is the epitome of teaching.

  • @troylangner7337
    @troylangner7337 3 роки тому +3

    I've searched high and low for exactly this, thank you so much.

  • @siaw0000
    @siaw0000 5 років тому +8

    Thanks a lot for these tutorials! I'm learning Pygame for a term project and they help a lot:)

  • @devansh5922
    @devansh5922 4 роки тому +16

    finally after serching so much found the tutuorial i needed

  • @raniabou-ismail4494
    @raniabou-ismail4494 5 років тому +46

    finally, thank you so much, my pygame wouldn't work and you fixed it!!!!!

    • @asishraz6173
      @asishraz6173 3 роки тому

      Anyone wants to learn Python through basic came can see this link:
      ua-cam.com/video/ijOGhZFeVGA/v-deo.html
      And let me know, whether you liked it or not

  • @shannexthedestroyer4037
    @shannexthedestroyer4037 2 роки тому +1

    I'm 28 and I started my codeing career with this video. thanks tim

  • @ganeshkrishnaprasad3785
    @ganeshkrishnaprasad3785 4 роки тому +1

    This tutorial was totally the best for beginners in my perspective and also I changed the colour of the rectangle to yellow (255, 230, 50).Thanks man

  • @yeaseulyoo1195
    @yeaseulyoo1195 5 років тому +13

    OMG Tim I made it! Thanks alot I had so much fun with your tutorial, pls make more for me !!! Your tutorial is easy to understand and clear .

  • @bzsgzs
    @bzsgzs 6 років тому +17

    Very well spoken and clearly explained concepts. Great work!!

  • @svijayiitk
    @svijayiitk 4 роки тому +1

    Best pygame/python tutorial I've ever learned. Thank you!
    Instantly subbed!

  • @xtechwarrior7063
    @xtechwarrior7063 5 років тому +2

    You are a life saver man, keep making these awesome videos, you deserve like a million subs.

  • @boopypasta
    @boopypasta 5 років тому +125

    Yay! Now I have a moving purple rectangle! (I changed the RGB to (200, 23, 255) to make a light purple color)

    • @frenzy9741
      @frenzy9741 5 років тому +32

      Me too! I also add some horizontal acceleration and friction to make it more fun. Now let's program GTA V 😂

    • @caliapster8720
      @caliapster8720 5 років тому +2

      wolf hahahahahahah

    • @joshuabaker2833
      @joshuabaker2833 4 роки тому +1

      @@frenzy9741 im tryna make a flight simulator

    • @ViratKohli-jj3wj
      @ViratKohli-jj3wj 4 роки тому +5

      @Jayant Jagtap r/woooosh

    • @saisreevani8190
      @saisreevani8190 4 роки тому

      love that color :)

  • @brianmartin6486
    @brianmartin6486 4 роки тому +6

    As someone who's been trying to learn pygame in python for a while now , this was very simplified and easy to follow . Thanks so much . :) Looking forward to learning with the others .

  • @fahad_hassan_92
    @fahad_hassan_92 6 років тому +9

    Extremely awesome and easy too understand video !

  • @EpochIsEpic
    @EpochIsEpic 4 роки тому +1

    This is SUPER helpful for a resume project I am working on. Thank you very much!

  • @person-vi6dm
    @person-vi6dm 4 роки тому +9

    I’m making a small game for my school project, this was really helpful!

  •  6 років тому +3

    Awesome tutorial and very good teacher. Thank you!

  • @america4algerian
    @america4algerian 5 років тому +2

    You deserve more than one like my friend unfortinatly its not possible....great job Thank you

  • @gouravchouhan1790
    @gouravchouhan1790 3 роки тому

    That's how tutorials should be, didn't know nothing at first but u made it eaaasyyyyy.❤️

  • @notoriouzmodz8711
    @notoriouzmodz8711 4 роки тому +4

    man, thank you for making this, its easy to understand, and it helps me a lot, you earned a like and a sub bro

    • @asishraz6173
      @asishraz6173 3 роки тому

      Anyone wants to learn Python through basic came can see this link:
      ua-cam.com/video/ijOGhZFeVGA/v-deo.html
      And let me know, whether you liked it or not

  • @diegojacinto4735
    @diegojacinto4735 5 років тому +22

    dude u are awesome, pls continue doin this

  • @Gridzontop
    @Gridzontop 2 роки тому

    THANK YOU SO MUCH THIS IS THE FIRST CODING VIDEO I'VE WATCHED WITH 0 ERRORS IN MY CODE THANK YOU MAY GOD BLESS YOU

  • @awesometoys7294
    @awesometoys7294 3 роки тому

    Thank God for Tech with Tim....boy have I came a long way!

  • @lisaroy1230
    @lisaroy1230 6 років тому +43

    bro you are awesome

  • @sankethb.k642
    @sankethb.k642 5 років тому +10

    Congratulations bro.
    When I was watching your series it had only 100 views you grew so fast in 2 months

    • @TechWithTim
      @TechWithTim  5 років тому +2

      Thanks man

    • @asishraz6173
      @asishraz6173 3 роки тому

      Anyone wants to learn Python through basic came can see this link:
      ua-cam.com/video/ijOGhZFeVGA/v-deo.html
      And let me know, whether you liked it or not

    • @teambundyuk4840
      @teambundyuk4840 3 роки тому

      @@asishraz6173 stop advertising!

  • @jacobrose9606
    @jacobrose9606 4 роки тому

    Thank you! Your work is very beneficial as a starting point, or a refresher!

  • @sayanaimash1280
    @sayanaimash1280 4 роки тому

    You helped me so much with my CS project work, thanks! Keep going!!!

  • @tristandombroski9677
    @tristandombroski9677 Рік тому +12

    Man... Crazy how this video helps. It's simple yet everything I was looking for the past few hours.

  • @aidanwansbrough7495
    @aidanwansbrough7495 5 років тому +3

    Really helpful!! Thanks :)

  • @greenjc12
    @greenjc12 2 роки тому

    The one tutorial I can finally make sense of! Thanks so much :D

  • @zarkthemuffin
    @zarkthemuffin 4 роки тому

    This is a really good introduction to pygame. Thank you so much.

  • @sanjeevansingh2123
    @sanjeevansingh2123 5 років тому +6

    For a beginner it's super 👌

  • @s2s456
    @s2s456 5 років тому +8

    Your such a gooooooooood teacher

  • @sammitchell3365
    @sammitchell3365 2 місяці тому

    Amazing, well explained. Thank you so much!

  • @Britishblue.
    @Britishblue. 3 роки тому

    Thanks so much for this. With just this one video I was able to make a complete game of pong by using this basic info.

  • @ekmeginuzerindekikotukuf2487
    @ekmeginuzerindekikotukuf2487 5 років тому +5

    I really thank you bro. Loves from Turkey

  • @lavinabhambra7611
    @lavinabhambra7611 6 років тому +4

    greatly explained video!!

  • @Siddhesh1123
    @Siddhesh1123 3 роки тому +1

    u have come such a long way from this video! well done!

  • @SA3LAD
    @SA3LAD 5 років тому +2

    Thanks!
    helped a lot, keep it up :)

  • @abhiramkidambi6666
    @abhiramkidambi6666 5 років тому +5

    How do you have 10k subscribers, that is so little for such a good teacher. Thank you, I learned something in pygame for once

    • @valteu
      @valteu 4 роки тому

      I read the comment, look how much subscribers he has now (11 months later):181 000 ...

    • @oli4665
      @oli4665 3 роки тому +1

      @@valteu look now

  • @ibrahimabdalla1642
    @ibrahimabdalla1642 4 роки тому +3

    WHY DID I NEVER KNOW TILL NOW THE MAGIC OF LIBRARIES!!! I AM SO PISSED AT MYSELF FOR NEVER USING PYGAME BEFORE NOW. THANK YOOOOOOOOOOOOUUUUUUUUUUUUUU!!!!!!!!!!!!!!!!!!!!!

    • @asishraz6173
      @asishraz6173 3 роки тому

      Anyone wants to learn Python through basic came can see this link:
      ua-cam.com/video/ijOGhZFeVGA/v-deo.html
      And let me know, whether you liked it or not

  • @pawankumargangwar6179
    @pawankumargangwar6179 5 років тому +2

    Thanx Tim, Good tutorial for beginner

  • @commanderjohn0077
    @commanderjohn0077 22 дні тому

    The way you teach is so good. You R like a professional Coding Teacher. Its so fun to watch event though i know these stuff. Thanks❤

  • @elliottandreasen4148
    @elliottandreasen4148 4 роки тому +6

    i did this to make sure that the square wasn't able to move out of the screen. if makes sure that fx the specific function K_LEFT doesn't work if you're too far to the left. (in this case, x = 0)
    if x > 0:
    if keys[pygame.K_LEFT]:
    x -= velocity
    if x < 460:
    if keys[pygame.K_RIGHT]:
    x += velocity
    if y > 0:
    if keys[pygame.K_UP]:
    y -= velocity
    if y < 440:
    if keys[pygame.K_DOWN]:
    y += velocity

  • @ryanyang6330
    @ryanyang6330 5 років тому +8

    Great tutorials, SUBSCRIBED! Helped me a lot with coding.
    Just wish you can explain a little bit more about the methods you used from pygame ( things like their required parameters or default parameters, and what do they return? what type is it?)
    I know I can basically use help() to see the details but if I can get more brief explanations from your tutorial, I could save a lot of time and work.
    Anyway thanks a lot for sharing.

    • @TechWithTim
      @TechWithTim  5 років тому +2

      Thank you and I do appreciate the feedback!

  • @RahulYadav-lm6mv
    @RahulYadav-lm6mv 4 роки тому

    Your explaination is very simple and easy to understand, thank you

  • @mohammedbasher7083
    @mohammedbasher7083 Рік тому

    I can't find a great enough way that fits you to thank you💯🙌

  • @derJoel
    @derJoel 6 років тому +5

    Hey, good video. Will you continue it?

  • @samban496
    @samban496 4 роки тому +6

    For anyone who has the rectangle showing for a brief moment when quitting the window It's because the below code:
    "pygame.draw.rect(win, (255, 0, 0), (x, y, width, height))
    "
    "pygame.display.update()"
    is not in line with the "for event in pygame.event.get():"
    So for example: (this is how it should be)
    |for event in pygame.event.get():
    | if event.type == pygame.QUIT:
    | run = False
    |
    |pygame.draw.rect(win, (255, 0, 0), (x, y, width, height))
    |pygame.display.update()
    and (this is how it shouldn't be):
    |for event in pygame.event.get():
    | if event.type == pygame.QUIT:
    | run = False
    |
    | pygame.draw.rect(win, (255, 0, 0), (x, y, width, height))
    | pygame.display.update()
    the positioning of your codes matters.

  • @kuyabala581
    @kuyabala581 3 роки тому

    Best tutorial ever. Thx for making this tutorial

  • @aashutoshsinghal280
    @aashutoshsinghal280 3 роки тому

    Marvelous Explanation!!!!
    Good Work.........

  • @vermiman
    @vermiman 5 років тому +20

    Bounds checking:
    if keys[pygame.K_LEFT] and x > 0:
    x -= vel
    if keys[pygame.K_RIGHT] and x < 460:
    x += vel
    if keys[pygame.K_UP] and y > 0:
    y -= vel
    if keys[pygame.K_DOWN] and y < 440:
    y += vel

    • @quakducc2274
      @quakducc2274 5 років тому

      If you add
      from pygame.locals import *
      You no longer need the pygame in front of K_UP, K_DOWN, etc. It's a pygame standard, so it's highly recommended.

    • @yesveryprofesionalnameyes6055
      @yesveryprofesionalnameyes6055 5 років тому +2

      I am so used to c++ and i am triggered whit and not being && and the condition in if not in (), and the : not being {}. I want to die. But it looks fins. Also rip the semi-colin.

    • @frenzy9741
      @frenzy9741 5 років тому

      @@yesveryprofesionalnameyes6055 LOL!!! I came from Python 3.7 and when I saw C++ it was confusing. It wasn't as flexible as Python is.

  • @niladrichatterji9140
    @niladrichatterji9140 3 роки тому +3

    Extra tip because I was Facing this problem:-
    If "import pygame, sys" isn"t responding or appearing colourless if you are using PyCharm, write "# noinspection PyUnresolvedReferences" a line before it without using any bnrackets or tuples.....

  • @jonasohrn
    @jonasohrn 4 роки тому

    Thank you ! I liked the tutorial very much.

  • @thereadingcafe7246
    @thereadingcafe7246 3 роки тому +1

    OMG YOU'RE SO GOOD MY PYGAMES KEPT HAVING ERRORS BUT THANKS TO YOU IT WORKS THX :DD

  • @asddsaasdfg2846
    @asddsaasdfg2846 3 роки тому +12

    2:05 Tim: pretty boring window
    Me: oh my gosh he opened a window🤯🤯

  • @brockpiano
    @brockpiano 3 роки тому +3

    Something I noticed while tinkering with the game's code is that your speed is tied to the framerate.
    edit: If you want to make the game 60fps, change the delay at line 16 to "16" instead of "100".
    edit 2: You will notice that you are noticeably faster than before. To remedy this, change the value of "vel" at line 12 to 0.8.

    • @andzhurt4827
      @andzhurt4827 Рік тому

      YOOoo that feels so nice

    • @brockpiano
      @brockpiano Рік тому

      @@andzhurt4827 lol i forgot i made this comment, at least it hekped

  • @techconclave6201
    @techconclave6201 3 роки тому

    Great Tutorial Series... Love the way you explain 👏👏👏

  • @emeraldthunder
    @emeraldthunder 3 роки тому

    I like this tutorial. It is helping me to really understand 2D game development in python.

  • @justask7016
    @justask7016 5 років тому +5

    When I hold down the keys, my rectangle stops moving. I have to press one key at a time in order for the rectangle to move a certain distance. How do I fix it so I can move it while holding down the keys?

    • @sushi_cat_og5411
      @sushi_cat_og5411 5 років тому

      @Jacob MANSFIELD Thank you this helped a lot because I had the same problem, thanks for the solution.

    • @blueduck2115
      @blueduck2115 3 роки тому

      @Jacob MANSFIELD thanks dude

  • @evanroderick91
    @evanroderick91 5 років тому +13

    When I run the program, the window quickly closes. I'm running the code via the command prompt on windows and editing it via Sublime text 3

    • @gzshrizzi5104
      @gzshrizzi5104 5 років тому +1

      Try using IDLE that comes with python

    • @Paul-rd5zk
      @Paul-rd5zk 4 роки тому +2

      I have the same issue did u find the solution? please reply!

    • @riksmits5526
      @riksmits5526 4 роки тому

      are you dutch?

    • @razmysignas7216
      @razmysignas7216 4 роки тому

      me too

    • @ToSemIdeia841
      @ToSemIdeia841 4 роки тому +4

      I'm having the same problem, but I'm in pycharm

  • @thestopmotion
    @thestopmotion 5 років тому +2

    Nice vid,
    helped me a lot!

  • @ilari90
    @ilari90 3 роки тому +1

    This series is amazing, I have learned lots of basic python stuff from it with almost "hello world" starting knowledge. I'm going on Tutorial #8 and helping guys in our class to learn basic python using this as material.
    For example I never could understand the Object-Oriented Programming in courses I went to in university, but using that in a this game project taught me how to use it and what it's good for.

  • @tahahasnain7603
    @tahahasnain7603 4 роки тому +57

    Hey everyone trying to learn code in quarantine

    • @Suo_kongque
      @Suo_kongque 4 роки тому +2

      Hiyo!

    • @Maedros11
      @Maedros11 4 роки тому

      u got me

    • @RomanReigns-ds8hs
      @RomanReigns-ds8hs 4 роки тому +1

      when i am running the code in sublime text editor , it opens pygame window and then closes immediately.
      Do you know why this is happening?

    • @RomanReigns-ds8hs
      @RomanReigns-ds8hs 4 роки тому

      @Finnbyte yeah I am opening in CMD and there is no error
      But that's ok with that main loop it works fine

    • @colwarsstudiobrickfilmandm8580
      @colwarsstudiobrickfilmandm8580 3 роки тому

      This tutorial is using 1.6.2 there are others up to date not that this one is bad it's just its 2 years old... but keep watching it's cool to see how far coding has come since 2 years ago

  • @vladkrstevski1482
    @vladkrstevski1482 5 років тому +3

    I like how you didn't even activate windows, other than that great video!

    • @disc_00
      @disc_00 4 роки тому +1

      Its useless tbh

  • @krypton9378
    @krypton9378 3 роки тому

    Damn ! I love this guy ..really men he is the best teacher you will found there..

  • @falconlin1011
    @falconlin1011 4 роки тому +1

    awesome explanation, very helpful.

  • @titotitoburg6298
    @titotitoburg6298 4 роки тому +3

    Hey friends, find some sample code for what he's doing, this is my second day coding so its not very good, but this is smooth movement of a polygon on a screen using the arrow keys.
    import sys
    import pygame
    import random
    pygame.init()
    WIDTH = 1000
    HEIGHT = 600
    FPS = 60
    RED = (255,0,0)
    GREEN = (0,255,0)
    BLUE = (0,0,255)
    YELLOW = (255,255,0)
    BLACK = (0,0,0)
    BACKGROUND_COLOR = BLUE
    polyx1 = 500
    polyy1 = 500
    polyx2 = 520
    polyy2 = 545
    polyx3 = 480
    polyy3 = 545
    polygon = [(polyx1,polyy1),(polyx2,polyy2),(polyx3,polyy3)]
    screen = pygame.display.set_mode((WIDTH,HEIGHT))
    game_over = False
    clock = pygame.time.Clock()
    pygame.key.set_repeat(1,1)
    pygame.display.set_caption("Smooth Movement")
    while not game_over:
    for event in pygame.event.get():
    print(event)
    if event.type == pygame.QUIT:
    sys.exit()
    if event.type == pygame.KEYDOWN:
    if event.key == pygame.K_LEFT:
    polyx1 -= 5
    polyx2 -= 5
    polyx3 -= 5
    elif event.key == pygame.K_RIGHT:
    polyx1 += 5
    polyx2 += 5
    polyx3 += 5
    elif event.key == pygame.K_UP:
    polyy1 -= 5
    polyy2 -= 5
    polyy3 -= 5
    elif event.key == pygame.K_DOWN:
    polyy1 += 5
    polyy2 += 5
    polyy3 += 5
    polygon = [(polyx1,polyy1),(polyx2,polyy2),(polyx3,polyy3)]
    screen.fill(BACKGROUND_COLOR)
    clock.tick(FPS)
    pygame.draw.polygon(screen, (YELLOW), polygon, 0)
    pygame.display.update()

  • @tahahasnain7603
    @tahahasnain7603 4 роки тому +4

    If anyone is having problems moving the rectangle left and right, here you go. (I cancelled the delay I had some issues).
    import pygame
    pygame.init()
    win = pygame.display.set_mode((500, 500))
    pygame.display.set_caption("First Game")
    x = 50
    y = 50
    width = 40
    height = 60
    vel = 5
    run = True
    while run:
    pygame.time.delay(50)
    for event in pygame.event.get():
    if event.type == pygame.QUIT:
    run = False
    keys = pygame.key.get_pressed()
    if keys[pygame.K_LEFT]:
    x -= vel

    elif keys[pygame.K_RIGHT]:
    x += vel
    elif keys[pygame.K_UP]:
    y -= vel
    elif keys[pygame.K_DOWN]:
    y += vel
    #pygame.time.delay(50)
    win.fill((0,0,0))
    pygame.draw.rect(win, (255, 0, 0), (x, y, width, height))
    pygame.display.update()
    pygame.quit()

  • @arjunshenoy3831
    @arjunshenoy3831 3 роки тому

    The square in the scene is actually draggable! LOL.. great tutorial!

  • @sjoerdhoppenbrouwers7222
    @sjoerdhoppenbrouwers7222 3 роки тому

    Really helpful video!! thanks!

  • @Aeztrest
    @Aeztrest 5 років тому +4

    hi tim u are the most one to programminger :) I'm turkish so my english is bad Im 14. and ı will be programminger in future. just u can know u are the besttttttttttt!!!!!!!

  • @irmuunn9758
    @irmuunn9758 5 років тому +3

    pygame has no init member error.
    please help!

  • @littleglitch5853
    @littleglitch5853 3 роки тому

    This is the best tutorial I've ever seen........... :)

  • @Otto_Heiskanen
    @Otto_Heiskanen 3 роки тому

    Thanks, you dont even know that how much u helped me

  • @Petesky.MusicProductions
    @Petesky.MusicProductions 6 років тому +3

    Nice tutorial senpai!

    • @boopypasta
      @boopypasta 5 років тому

      I agree with you Peter~Kun!

  • @icecreamguy2786
    @icecreamguy2786 5 років тому +6

    my window only stays open for a second why??? it isnt until i add in the event checking that the window stays up, why does your window stay open at the begining of the video tim??

    • @myFriend22198
      @myFriend22198 5 років тому +2

      I think u should add delay

    • @user-sy1xx2mn2d
      @user-sy1xx2mn2d 5 років тому +1

      first, in the beginning of the code, write "import time"
      then, write in the end of the code "time.sleep (the secs you want the window to wait).

    • @MohamedHassan-iy3bz
      @MohamedHassan-iy3bz 5 років тому

      the same happened with me then i checked and it was this if statement, i types () after QUIT thats why python couldn't execute it,
      if event.type == pygame.QUIT:

    • @user-xc7sb6tm1f
      @user-xc7sb6tm1f 5 років тому

      @MegaMogul2 I typed "while True:" then I put his code in but now I cannot get the window that pops up to close, do you know how to fix this?
      Never mind, I just had to watch some more of the video lol

  • @sharonportocarrero6806
    @sharonportocarrero6806 3 роки тому

    OMGGG LOVE YOUR VIDEOS THNXX A LOT

  • @yosefmizrahi2288
    @yosefmizrahi2288 4 роки тому

    helped a lot, thank you very much

  • @lisaroy1230
    @lisaroy1230 6 років тому +7

    plz keep posting video

  • @J_Bollich
    @J_Bollich 6 років тому +7

    pygame.draw.rect(win, (255, 0, 0), (x ,y , width, height)) did not work

    • @yesveryprofesionalnameyes6055
      @yesveryprofesionalnameyes6055 5 років тому +2

      Did you define all the variables(win=... , x=...., y=...,width=....,height=... (... Is code inside the variabsles)

    • @badumtss3977
      @badumtss3977 4 роки тому

      @Fazil Ahmed it's defined in the beggining, - win = pygame.display.set_mode((500,500))

  • @shinratenten5686
    @shinratenten5686 4 роки тому

    Thanks man it really helped me a lot !!!! keep it up

  • @faridjafarov3884
    @faridjafarov3884 5 років тому +2

    thanks very much for this video

  • @Volataxx
    @Volataxx 4 роки тому +15

    Why does the Pygame window close immediately after running?

    • @valentinoito1552
      @valentinoito1552 4 роки тому

      did you do the while loop? it shouldn't close if you did it.

    • @noobstudios4457
      @noobstudios4457 4 роки тому

      I am facing the same problem...... someone answer plz

    • @valentinoito1552
      @valentinoito1552 4 роки тому +1

      @@noobstudios4457 I think it's because there's some errors in your code. If there is no error in your code but still keeps closing, try opening your file using Run command by right clicking the windows icon, then selecting 'run'. On the Run command, type your file name, and then adding ' / K' after that. This should stop the window from closing automatically.

  • @myperspective5091
    @myperspective5091 5 років тому +5

    Is Pygame more like a bridge, a next step, or an alternative to Scratch?
    I have made games with Scratch but I haven't learned python yet ,because I felt lost with the online educational tutorials because they started out too basic. They were too general with out being related to any field of study.
    I wanted to get into robotics as a hobby, but just buying a robot with say a Raspberry Pi which uses raspbian to program it wouldn't teach me enough to expand my knowledge past basic robotics.
    I couldn't even learn Open CV or anything else like understanding neural networks.

    • @alfonslindg
      @alfonslindg 5 років тому +1

      i actually think you can program Raspberry Pi with python

    • @myperspective5091
      @myperspective5091 5 років тому

      +AlfonsL
      👍

    • @wonkysouceaasdsad9664
      @wonkysouceaasdsad9664 5 років тому +1

      i think python is the easyest programming language, learn it from the bases. Neural networks requires python and linear algebra knowledge.

  • @lephilistin
    @lephilistin 3 роки тому

    Great tutorial. Thanks!

  • @francescodefulgentiis907
    @francescodefulgentiis907 3 роки тому

    just, the best tutorial ever

  • @bugibugi5400
    @bugibugi5400 4 роки тому +3

    pygame.error : video system not initialized
    How to fix this? I already have pygame.init() in my first line of code

    • @shakked95
      @shakked95 4 роки тому

      hi.
      had the same eror.
      i worte
      if event.type == pygame.quit()
      insted of
      if event.type == pygame.QUIT

    • @sander15.
      @sander15. 4 роки тому

      @@shakked95 hey i tried what u said but now it says "intax error" so now what? can u help me?

    • @shakked95
      @shakked95 4 роки тому

      @@sander15. well i can try. can you copy and paste the error and the code that caused it?

    • @sander15.
      @sander15. 4 роки тому

      shakked95 dont worry i just searched for many places and i just got the answer thank u!!

  • @leeroyjenkins5414
    @leeroyjenkins5414 6 років тому +3

    My window does not close when I try to quit but no error shows up help.

    • @matteoscalvini6665
      @matteoscalvini6665 6 років тому +1

      maybe you did not write it in upper case! (i answer for those who have your same problems! I had it too)

    • @Anand-S23
      @Anand-S23 5 років тому

      One way to fix it is if you import sys when you import pygame:
      import pygame, sys
      run = True
      while run:
      for event in pygame.event.get():
      if event.type == pygame.QUIT:
      sys.exit()

  • @smitanandy8443
    @smitanandy8443 3 роки тому

    Thanks for the tutorial in IDLE

  • @marcdavies7046
    @marcdavies7046 Місяць тому

    Thank you for your tutorial!