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.
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
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.
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. :)
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.
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.
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
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?
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.
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.
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 )
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
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?
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)
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?
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
@@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?
@@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?
# 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()
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.
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
thanks, even if two years passed this tutorial helps me
Thank you very much for this tutorial, I was having a lot of trouble with this part. Clean and straight to the point.
Glad it helped!
Bro your channel is a hidden gem, awesome content
Thank you!
Ma dude you are an angel that helped me in my dark hour
Glad to hear it!
Man you're so damn good at explanation for real and only having 13k it's very undervalued :(
Thanks a lot! I'm just glad the videos are helpful :)
Love your videos man, keep it up
Thanks!
nice tutorial i implement this paused menu to the tower defence game
Nice! Combining two tutorials :)
thanks for the explanation all of them really really helps me thanks for making this vedeos
You're welcome, glad you found it useful
The thing I was waiting for!
Good timing :)
@@CodingWithRuss im still waiting on that discord server :(
@@CodingWithRuss and im learning java and lua now :)
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.
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.
Fock u pay me😂
I really enjoyed your all video nice explanation sir
Please teach us how to create a 3d game using pygame
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.
awesome. just so you know, i smashed the like button and bell! if there are any other button to smash, tell me!
Thank you :)
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
life saver
i love you random internet person
thanks for the good video!👍
Glad you liked it
After rewriting the code in 5:09, i press space and the text doesnt dissapear?
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.
Great video!
Thanks!
👏
🙂
Oh...
Real nice...
✅✅✅✅
Thanks
@@CodingWithRuss
You are always welcome and I thank you for your wonderful videos!
keep getting an error "unident doesnt match with any other indentation level"
and now i get a black screen with not responding when i run it
He never got an answer
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. :)
@@peekahbooh6985 A year of coding experience later and I'm wishing my biggest problem with my code was just a simple unindent error
very nice men! thanks a lot
Thanks
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.
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.
@@CodingWithRuss Thanks for the advise man! I managed to get it working! Appreciate it !!!
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
hey can u tell me that how did you save that images? i am on IDLE on MacBook so please explain me how!
That's awesome
Thank you
Video muito esclarecedor! Obrigado amiigo!
Hi, I been trying to do this menu, but I got a black screen for some reason
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.
how and where should i put my game code? please help me
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?
where did you get the images from??
If you alrready have a game for the code written, where would you add this code ? Thank u
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.
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.
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?
Thanks so much for this video.
I can put a image on the background of the options menu? Or just fill with colors?
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.
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.
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 )
Hey, I enjoy watching your videos! Are you in audea btw..
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
Do you mean in the editor? I use sublime text editor so it may look different to yours if you are using something else.
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?
Thanks!!!
Круто😌👍
Spasibo :)
thank you ,,,,that's Great but I want to ask about (platformer game) ?
THE Question is how I make animation to sprite? example enemy?
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)
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?
when i press back it quits the application are u able to help please
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
Sir can you make tutorial how to add punch block and break block in python pygame
thanks
Hey, how about a character select menu? How can i make that?
the font.render just gives me an error saying "'str' object has no attribute 'render'"
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
@@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?
@@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?
@@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?
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 :/
# 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()
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
I haven't tested it specifically with full screen games but it should work. How did you get on with it?
@@CodingWithRuss i made an event that adjust the screen
Sir can you make tutorial how to create 2d minecraft in python pygame
What happened to your website?
When I tried to access it, it says "Account suspended" even though I haven't done anything.
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.
@@CodingWithRuss Ohhk, thanks for the heads up and keep up the good work.
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 !
very usefull but im still at 3/13 on that game :))))))))))))))))))
Haha there's no rush :)
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
New video?
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 :)
@@CodingWithRuss okayy :)))
Where is the code of Button Class??????😡😡😡
Github link is in the video description
2:42
NOTHING WORKS IN ANY OF THESE VIDEOS
Learn how the code works and what went wrong