How to Create Menus in Python Games! (PyGame Tutorial)

preview_player
Показать описание
Several people have asked how to implement menus in their PyGame python games, and here at LeMaster tech we aim to please!!

Code demonstrated in this video is available for download here:

Check out my personal channel for more fun science content!

This tutorial shows everything you will need to know to incorporate menus into your PyGame video games developed in the python programming language! We quickly set up a PyGame game window together, then show how to use a set of toggling buttons to control whether or not the menu is active, then we set up a class for buttons so we don't have to keep rewriting the code, and then demonstrate how to use the clicked feedback from each button to affect the game!

If you found this video useful and want to become a SUPER SUPPORTER, feel free to check out my Patreon here, all tiers are so greatly appreciated!!:

As always if you have questions, comments or concerns about what you saw here, feel free to leave a comment on the video about it and I'll get back to you as soon as I can! Don't forget to leave a like on the video and subscribe to the channel for all of the great content there!

Timestamps:
00:00 Introduction and Demo
1:45 Setting Up Pygame
5:30 Create Menu and First Button
15:49 Set Up Button Class
24:23 Adding More Buttons and Functionality
Рекомендации по теме
Комментарии
Автор

Thanks man, really appreciate your hard work

pogmij
Автор

Short and sweet.
Main loop logic took me some time to get.
Basically, if "main menu" is active and any button is pressed on it - switch it off.
Otherwise look for if the "main menu" button is pressed in "game" mode and if the menu_command variable is > 1
print it on screen.

flioink
Автор

Thank you! I'm doing my A level coursework and this has been very useful!

shreyak
Автор

Great job as usual, if you’re looking for ideas of other languages, I’d really like to see more on C++. Can never seem to get my head around that one!

rethanon
Автор

Great video. Can you please do a video on how to make submenus using this same code?

thebossman
Автор

thanks, this is helping with my A level work but im working onwards from this point and im trying to replicate this for a separate menu but the menu only opens if i hold down where the button was, i let go and if goes back. i was wondering what makes a new menu open permanantly after pressing a button.

succman
Автор

Now how do I link the menu, for example, the part to buy managers in the idle clicker (that you created a long time ago) for example? And that the game continues to work? Because I try and when I click on a bar with the mouse, it doesn't load the animation. Or in the menu I put the buttons to buy the managers and they do nothing.

BossyPK
Автор

Hey - I have no idea if you'll reply to this comment but after making the buttons which lead off into the different terminals (e.g. "Button 1 was clicked") 1. How did you get everything else to disappear - what part of the code did that? 2. If the button was made to go to a different part of the program that was a game, for example, would you just insert the code for that game in that loop?

fifi_x
Автор

How do we connect the game to the main menu if the game is in another py . Thank you

nacchi-yan
Автор

Hi
Do you know how I could make my pygame update itself by downloading new files from the internet and installing them?
Thank you in advance

Dyotar
Автор

Hey bro, can you provide a bit of code that will allow me to put a background to my main menu ?

AAKSCaptures
Автор

what is this error AttributeError: 'pygame.Surface' object has no attribute 'collidepoint'

usmanamjad