How to Create a Menu in Pygame

Поделиться
HTML-код
  • Опубликовано: 1 янв 2025

Комментарии • 112

  • @cantina_informatica
    @cantina_informatica 11 дней назад

    thanks, even if two years passed this tutorial helps me

  • @dansassis6770
    @dansassis6770 2 года назад +27

    Thank you very much for this tutorial, I was having a lot of trouble with this part. Clean and straight to the point.

  • @pandazorrao458
    @pandazorrao458 2 года назад +16

    Bro your channel is a hidden gem, awesome content

  • @OmongosCharlie
    @OmongosCharlie 7 месяцев назад +2

    Ma dude you are an angel that helped me in my dark hour

  • @modnayashalava8212
    @modnayashalava8212 2 года назад +2

    Man you're so damn good at explanation for real and only having 13k it's very undervalued :(

    • @CodingWithRuss
      @CodingWithRuss  2 года назад

      Thanks a lot! I'm just glad the videos are helpful :)

  • @kobalt9299
    @kobalt9299 2 года назад +7

    Love your videos man, keep it up

  • @charlesmendoza4660
    @charlesmendoza4660 Год назад +2

    nice tutorial i implement this paused menu to the tower defence game

  • @tarigaming7395
    @tarigaming7395 2 года назад +1

    thanks for the explanation all of them really really helps me thanks for making this vedeos

    • @CodingWithRuss
      @CodingWithRuss  2 года назад

      You're welcome, glad you found it useful

  • @ToujoursIris
    @ToujoursIris 2 года назад +2

    The thing I was waiting for!

    • @CodingWithRuss
      @CodingWithRuss  2 года назад

      Good timing :)

    • @ToujoursIris
      @ToujoursIris 2 года назад

      @@CodingWithRuss im still waiting on that discord server :(

    • @ToujoursIris
      @ToujoursIris 2 года назад

      @@CodingWithRuss and im learning java and lua now :)

  • @plexus2000
    @plexus2000 2 года назад

    Great this is what i need because i'm working on a game with the knowledge that i've gotten from you. Although I am having trouble trying to figure out how to make them work like if i click the video setting you can actually customize the settings.

    • @dominicballinger6536
      @dominicballinger6536 2 года назад

      Set a variable at the start of the script that affects the display surface/window. Then use the input to change the variable in the main game loop.

    • @Sourcecodemastergoaheadcheater
      @Sourcecodemastergoaheadcheater 11 месяцев назад

      Fock u pay me😂

  • @coderunner743
    @coderunner743 2 года назад +5

    I really enjoyed your all video nice explanation sir
    Please teach us how to create a 3d game using pygame

    • @CodingWithRuss
      @CodingWithRuss  2 года назад

      Thanks. Pygame can't do real 3D, just raycasting, but there are other libraries that can do it, so perhaps in the future I will try some 3D games too.

  • @MahmudShuaib
    @MahmudShuaib 2 года назад +1

    awesome. just so you know, i smashed the like button and bell! if there are any other button to smash, tell me!

  • @Kubar38
    @Kubar38 Год назад +20

    For anyone having a problem such as buttons on the same coordinates in submenus gets automatically clicked, make a variable: clicked = False and set it to True whenever a button is clicked and make buttons clickable only if clicked is False. Set clicked back to False after the pygame.MOUSEBUTTONUP is triggered. For example:
    if button.draw(screen) and not clicked: # if button.draw(screen) and clicked == False:
    do_something()
    clicked = True
    for event in pygame.event.get():
    if event.type == pygame.MOUSEBUTTONUP:
    clicked = False

  • @danuzota2265
    @danuzota2265 2 года назад +1

    thanks for the good video!👍

  • @garagebandersorg3343
    @garagebandersorg3343 Год назад

    After rewriting the code in 5:09, i press space and the text doesnt dissapear?

  • @derar5555
    @derar5555 2 года назад +3

    Hi there. Thanks a lot
    I'm having trouble creating various menus with Pygame using your method, since some of the menu buttons, although on different menu screens, share the same coordinates. So once one gets pressed, the next screen detects the button still being pressed and automatically triggers as well.

  • @yzhkkhzy
    @yzhkkhzy Год назад +1

    Great video!

  • @zhizhideng
    @zhizhideng 8 месяцев назад +2

    👏

  • @SkyFly19853
    @SkyFly19853 2 года назад +1

    Oh...
    Real nice...
    ✅✅✅✅

    • @CodingWithRuss
      @CodingWithRuss  2 года назад +1

      Thanks

    • @SkyFly19853
      @SkyFly19853 2 года назад

      @@CodingWithRuss
      You are always welcome and I thank you for your wonderful videos!

  • @Ray-sb8qi
    @Ray-sb8qi 2 года назад +3

    keep getting an error "unident doesnt match with any other indentation level"

    • @Ray-sb8qi
      @Ray-sb8qi 2 года назад +2

      and now i get a black screen with not responding when i run it

    • @kinge8531
      @kinge8531 9 месяцев назад +1

      He never got an answer

    • @peekahbooh6985
      @peekahbooh6985 9 месяцев назад +1

      Some interpreters use spaces as indentation, some use the 'Tab' key. If you've copy and pasted code from Russ, he has his settings set to a 'two space indentation'. Most interpreters are factory set to the tab option. Anytime you go into an 'IF' statement, or define a function, you indent the code. Mix and matching indentation by copy and pasting was a mistake I made - I'm almost certain this is your error. Highlight the code, and you should be able to see either dots (spaces) or a horizontal line (tabs) on the left hand side of your screen. Match the indentation using this as a guide, replacing spaces with tabs, or vice versa, and you should be able to continue. :)

    • @Ray-sb8qi
      @Ray-sb8qi 8 месяцев назад

      @@peekahbooh6985 A year of coding experience later and I'm wishing my biggest problem with my code was just a simple unindent error

  • @dubpper98
    @dubpper98 2 года назад

    very nice men! thanks a lot

  • @IWIMugriwara
    @IWIMugriwara 2 года назад +3

    Hi Coding Russ, have been watching most of your tutorials. Right now I am trying to create a function to pause the game inside Pygame. Do you have a video on it or is there any way you can guide me on it? Much appreciated for all your help.

    • @CodingWithRuss
      @CodingWithRuss  2 года назад +1

      Hello, to pause a game you can have a variable like "paused = False". Then put your game code inside an if statement "if paused = False:". This way all the code inside that will only run as long as your game is NOT paused. So when you do pause the game (you'll need to add your event for that separately), you can just set the paused variable to True.

    • @IWIMugriwara
      @IWIMugriwara 2 года назад +1

      @@CodingWithRuss Thanks for the advise man! I managed to get it working! Appreciate it !!!

  • @arpitplayz9046
    @arpitplayz9046 2 года назад

    I am getting an error saying module 'button' has no attribute 'Button'.
    And i checked there was a attribute The class Button. What should do why the menu.py dont showing and also I imported button in menu.py

  • @xoxo.lxly.26
    @xoxo.lxly.26 Месяц назад

    hey can u tell me that how did you save that images? i am on IDLE on MacBook so please explain me how!

  • @atharvkumar2564
    @atharvkumar2564 2 года назад +1

    That's awesome

  • @Anonimo_por_escolha
    @Anonimo_por_escolha Год назад

    Video muito esclarecedor! Obrigado amiigo!

  • @MrLOLYouTube
    @MrLOLYouTube Год назад

    Hi, I been trying to do this menu, but I got a black screen for some reason

    • @CodingWithRuss
      @CodingWithRuss  Год назад

      You may just have a typo somewhere. Check the code in the video description and see if you can find any differences that might be causing the issue.

  • @renn379
    @renn379 Год назад

    how and where should i put my game code? please help me

  • @OYMInternetRadio
    @OYMInternetRadio Год назад

    Hi, Good info so I went to github, downloaded your files and ran pyinstaller. It came up with an error saying "false" not defined and when I tried to open the main.py file, visual studio and the Idle showed a screen full of text, no formatting?

  • @alphamaine2714
    @alphamaine2714 Год назад

    where did you get the images from??

  • @BccollioB
    @BccollioB Год назад

    If you alrready have a game for the code written, where would you add this code ? Thank u

    • @CodingWithRuss
      @CodingWithRuss  Год назад

      You merge the code into what you already have written, so you would insert this into the relevant sections of your own code and tweak it to suit.

  • @tristandombroski9677
    @tristandombroski9677 2 года назад

    Wait... So I don't even really need Tkinter for buttons? the first thing I noticed was no import for Tkinter. Wish I could find the tutorial I watched a few days ago and point the guy in this direction... I like the way you do buttons.

  • @loli-chan7146
    @loli-chan7146 3 месяца назад

    Hey man, I might be late but I got something to ask. The else statement on game pause doesnt disappear on mine. You know any fixes?

  • @ElaineFlorMS
    @ElaineFlorMS 2 года назад

    Thanks so much for this video.
    I can put a image on the background of the options menu? Or just fill with colors?

    • @CodingWithRuss
      @CodingWithRuss  2 года назад +1

      Hi, yes you can change the background image and anything else. Just load in the image and blit it on the screen instead of filling the background.

  • @saitama9994
    @saitama9994 2 года назад

    Awesome video. I have a little problem where my submenu buttons are in the exact same place as the menu button. When I click a menu button, the program goes through and also clicks the submenu button. Is there a way I can delay the click or something? I noticed that in this video, your buttons are not in the same place so that problem may have not come up.
    Edit: I added a "clicked" check and it worked.

  • @justin7oo994
    @justin7oo994 2 года назад +1

    Very nice tutorial I'm kinda new I followed some of your game tutorials and they are amazing I learnt so much and I also had a question what os do you use (i know its windows but just asking )

  • @valeantigot6390
    @valeantigot6390 2 года назад

    Hey, I enjoy watching your videos! Are you in audea btw..

  • @nickda1
    @nickda1 Год назад

    how did you get that bar on the side of your screen on the python i have got its just a window with no menu bar at top all it says is the path i run it from

    • @CodingWithRuss
      @CodingWithRuss  Год назад

      Do you mean in the editor? I use sublime text editor so it may look different to yours if you are using something else.

  • @greatpigeons4741
    @greatpigeons4741 7 месяцев назад

    This is really helpful but i keep running into a problem where it says:
    resume_button = button.Button(304, 125, resume_img, 1)
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    TypeError: Button.__init__() missing 2 required positional arguments: 'size_x' and 'size_y'
    Any fixes?

  • @ratmadness4858
    @ratmadness4858 2 года назад

    Thanks!!!

  • @Dayplaylist
    @Dayplaylist 2 года назад +1

    Круто😌👍

  • @hazemhazem4619
    @hazemhazem4619 2 года назад

    thank you ,,,,that's Great but I want to ask about (platformer game) ?

    • @hazemhazem4619
      @hazemhazem4619 2 года назад

      THE Question is how I make animation to sprite? example enemy?

    • @hazemhazem4619
      @hazemhazem4619 2 года назад

      I added some sprite to your code ,its food (hamburger).and with your code in enemy class I made it move, and with code in coin class I made a (score = 5) . every thing is very well (thank you alot)
      but.............! when I added onther sprite (dragon) with enemy code to move and kill ( code if died player & game over), i want to change look (animation) when it move. so I add code (animation) from player class ..... that's ok without any errore. but I can't control (animation) , dragon move without animation one socend then it work animation but very fast, I can't conect between (counter) & (move_counter)

    • @hazemhazem4619
      @hazemhazem4619 2 года назад

      I added some sprite to your code ,its food (hamburger).and with your code in enemy class I made it move, and with code in coin class I made a (score = 5) . every thing is very well (thank you alot)
      but.............! when I added onther sprite (dragon) with enemy code to move and kill ( code if died player & game over), i want to change look (animation) when it move. so I add code (animation) from player class ..... that's ok without any errore. but I can't control (animation) , dragon move without animation one socend then it work animation but very fast, I can't conect between (counter) & (move_counter)
      THE Question is how I make animation to sprite? example enemy?

  • @dqew1664
    @dqew1664 2 года назад

    when i press back it quits the application are u able to help please

    • @markangier8124
      @markangier8124 2 года назад

      i had the same issue, you can't have the back button on top of where the quit button was, because when you return to the main menu it will think you're clicking quit. hope this helps anyone with the same problem

  • @NDNGR
    @NDNGR 2 года назад

    Sir can you make tutorial how to add punch block and break block in python pygame

  • @usmanamjad1409
    @usmanamjad1409 2 года назад

    thanks

  • @emiliaserra1333
    @emiliaserra1333 Год назад

    Hey, how about a character select menu? How can i make that?

  • @daviddedank
    @daviddedank Год назад

    the font.render just gives me an error saying "'str' object has no attribute 'render'"

    • @CodingWithRuss
      @CodingWithRuss  Год назад

      Did you define your font the same way as I did in the video? The error message is saying that your "font" variable is defined as a string

    • @daviddedank
      @daviddedank Год назад

      @@CodingWithRuss for me the font.render makes the error. for u it acts like a command/function but for me it doesnt exist. did u make a render class?

    • @CodingWithRuss
      @CodingWithRuss  Год назад

      @@daviddedank No, render is built into pygame. I did define my font variable earlier on like this:
      font = pygame.font.SysFont("arialblack", 40)
      Do you have the same code?

    • @daviddedank
      @daviddedank Год назад

      @@CodingWithRuss well no i am trying to append this to my current snake game. i have tried to follow the tutorial but it's coming up with errors. wanna discuss this elsewhere?

  • @soop8765
    @soop8765 2 года назад

    I dont get the ability to close the window even after putting in the exact same code as yourself. My window just stays locked open :/

    • @martinparalic7999
      @martinparalic7999 Год назад

      # the same problem I had in Spyder, use pygame.display.flip()
      # try / except modification helps close window in case of other errors
      while run:
      screen.fill((52, 78, 91))
      if game_paused == True:
      pass
      else:
      draw_text("Press SPACE to pause", font, TEXT_COL, 160, 250)
      try:
      for event in pygame.event.get():
      if event.type == pygame.QUIT:
      run = False
      if event.type == pygame.KEYDOWN:
      if event.key == pygame.K_ESCAPE:
      run = False
      if event.key == pygame.K_UP:
      pass
      if event.key == pygame.K_DOWN:
      pass
      if event.key == pygame.K_KP_ENTER or event.key == pygame.K_RETURN:
      pass
      if event.key == pygame.K_SPACE or event.key == pygame.K_TAB:
      print("pause")
      game_paused = True
      pass
      except :
      run = False
      pygame.display.flip()
      pygame.display.quit()

  • @gutsjoestar7450
    @gutsjoestar7450 Год назад

    im here because when i tried this, my menu don't adjust to fullscreen, the rest is just blank white, i hope its explained in the video

    • @CodingWithRuss
      @CodingWithRuss  Год назад

      I haven't tested it specifically with full screen games but it should work. How did you get on with it?

    • @gutsjoestar7450
      @gutsjoestar7450 Год назад

      @@CodingWithRuss i made an event that adjust the screen

  • @NDNGR
    @NDNGR 2 года назад

    Sir can you make tutorial how to create 2d minecraft in python pygame

  • @Tuff0
    @Tuff0 2 года назад

    What happened to your website?
    When I tried to access it, it says "Account suspended" even though I haven't done anything.

    • @CodingWithRuss
      @CodingWithRuss  2 года назад

      I am switching it to a different hosting provider, which is taking a bit longer. The "account suspended" error is referring to the website but it should be up and running again soon! The source code for these videos is on my github as well so in the meantime you can still access it there if you need to.

    • @Tuff0
      @Tuff0 2 года назад

      @@CodingWithRuss Ohhk, thanks for the heads up and keep up the good work.

  • @TiktokkGames
    @TiktokkGames 2 года назад

    Can you do a tutorial for a game who connect to tiktok live comments,donations,followers,likes and the game react to all descbribe,thank you !

  • @MaxStudioCG2023
    @MaxStudioCG2023 2 года назад +1

    very usefull but im still at 3/13 on that game :))))))))))))))))))

  • @Jackson141vja
    @Jackson141vja Год назад

    You could simply create a function or class that would draw the screen with all the buttons on command
    For example:
    class menu:
    def __init___(self):
    pass
    #Initializes main
    def main(self):
    example1.draw()
    example2.draw()
    def options(self):
    example4.draw()
    example5.draw()
    menu.main()
    menu.options()
    and so

  • @ToujoursIris
    @ToujoursIris 2 года назад

    New video?

    • @CodingWithRuss
      @CodingWithRuss  2 года назад

      Yup, new game has been in the works since I finished the fighting game! It's taking a while to finish though, life getting in the way :)

    • @ToujoursIris
      @ToujoursIris 2 года назад

      @@CodingWithRuss okayy :)))

  • @暗号化
    @暗号化 Год назад

    Where is the code of Button Class??????😡😡😡

  • @thesoupbird
    @thesoupbird Год назад

    2:42

  • @AidenGriffin316
    @AidenGriffin316 6 месяцев назад +1

    NOTHING WORKS IN ANY OF THESE VIDEOS

    • @1DontNoclip
      @1DontNoclip 2 месяца назад +1

      Learn how the code works and what went wrong