Game Development in Python 3 With PyGame - 11 - Buttons p. 1

sentdex · Beginner ·🛠️ AI Tools & Apps ·11y ago

Key Takeaways

This video tutorial covers creating buttons in PyGame using Python 3, demonstrating how to draw rectangles and add text and interactivity to create a simple button illusion.

Full Transcript

hey guys what is going on welcome to another P game tutorial video in this video we're going to be talking about how we can create buttons in py game so there's no real way built into P game for us to like just easily make buttons but we can make our own way using other things that are built into P game so you can use these sorts of things that I'm about to show you to do all all kinds of things it just so happens that button is one of the things that we can combine all these tools together to use but you can use the tools that I'm about to show you through this little kind of minseries of buttons to do a lot of really cool stuff with pi games so anyway let's go ahead and get started so the way I Envision it is we're going to have this intro screen you've got a bit racy and then we'll have like a button here and it says play and then when we click it it'll play the game and then a button over here that says quit and when we quit click it it will quit I can't speak quit the game um so that's what we're going to cover now so first of all um we want a red button and a green button so we already have red defined but we need to Define green so we'll just say green equals um 0 200 and z and so we've defined green and then now we're going to come down to our game intro which will be right here and basically right before the game display. update is where we're going to add some new code so the starting point of our button are just going to be rectangles right we just need a couple rectangles and that will be a starting point for a button then we add some text then we add some interactiveness and then functionality when clicked so the first step to this process is just having some rectangles so that's easy enough so we can have py game. draw. where do we want to draw them to the game display um what color do we want this rectangle to be we'll say green um and then the information on the button so the top left um X and Y so we'll do um we'll do 150 550 and then 150 and then and let's go ahead and save and run that and see see where that is okay uh see Let's do let's try 450 instead that's better so we've got this button here and then we would want to add another button here so let's close out of this and let's just copy this copy and paste and now we want this button to be red and and instead of being uh an X of 150 we we'll make this x 550 and now we've got our two rectangles obviously they're absolutely useless they're just Blobs of color but as you'll find and as I've tried to kind of point out as we've go gone through these series a lot of things not only in games but just in programming in general there more Al like illusions of things so guies in general or graphical user interfaces are not really inherent to computers but they're inherent to humans like the users we like to see something that's interactive we we'd rather use a guey than a text based module that's why people have like desktops with icons and they don't just use a command line for the most part obviously if you're like you know a system administrator or something you're you use probably you know bash a lot or something like that but but for most people they find it far more intuitive to use goys but with um with computers that that it's just not the way it works like when I click on this the computer isn't like oh he is clicking in a green box but we think that you know in a button for example and you'll see um anybody who uses our our game and and sees our button and stuff it will feel very very natural to them but at the end of the day it's just um like an illusion of a button but it's not really a button at all you know there is no spoon so so anyway um so yeah so right now it's just a rectangle but um we'll see soon how we can convert that rectangle into a simple enough button so uh we're going to be covering that in the next video so stay tuned for that as always thanks for watching thanks for all the support and subscriptions and until next time

Original Description

See http://pythonprogramming.net for sample code PyGame with Python 3 Playlist: http://www.youtube.com/playlist?list=PLQVvvaa0QuDdLkP8MrOXLe_rKuf6r80KO In this PyGame with Python 3 tutorial, we cover the idea of button creation with PyGame. At the time of me making this video, there is no built-in button creating functionality with PyGame. Luckily, however, PyGame does provide us with enough tools to just create our own button function. http://seaofbtc.com http://sentdex.com http://hkinsley.com https://twitter.com/sentdex Bitcoin donations: 1GV7srgR4NJx4vrk7avCmmVQQrqmv87ty6
Watch on YouTube ↗ (saves to browser)
Sign in to unlock AI tutor explanation · ⚡30

Playlist

Uploads from sentdex · sentdex · 0 of 60

← Previous Next →
1 Matplotlib Python Tutorial Part 1: Basics and your first Graph!
Matplotlib Python Tutorial Part 1: Basics and your first Graph!
sentdex
2 Python Encryption Tutorial with PyCrypto
Python Encryption Tutorial with PyCrypto
sentdex
3 Python's Logging Function
Python's Logging Function
sentdex
4 wxPython Tutorials 1: Making Windows GUIs with Python : Installing + 1st window!
wxPython Tutorials 1: Making Windows GUIs with Python : Installing + 1st window!
sentdex
5 wxPython Tutorials 2: Making Windows GUIs with Python: Customizing Window Parameters
wxPython Tutorials 2: Making Windows GUIs with Python: Customizing Window Parameters
sentdex
6 wxPython Programming Tutorial 3: Menu Bar and Menu Button
wxPython Programming Tutorial 3: Menu Bar and Menu Button
sentdex
7 wxPython Programming Tutorial 4: Panels
wxPython Programming Tutorial 4: Panels
sentdex
8 wxPython Programming Tutorial 5: User Input Saved To Variables
wxPython Programming Tutorial 5: User Input Saved To Variables
sentdex
9 wxPython Programming Tutorial 6: Multiple Choice Input
wxPython Programming Tutorial 6: Multiple Choice Input
sentdex
10 wxPython Programming Tutorial 7: Adding Static Text and Colors
wxPython Programming Tutorial 7: Adding Static Text and Colors
sentdex
11 wxPython Programming Tutorial 8: Custom Button Images
wxPython Programming Tutorial 8: Custom Button Images
sentdex
12 wxPython Programming Tutorial 9: Tool Bar Items and Sub Menus!
wxPython Programming Tutorial 9: Tool Bar Items and Sub Menus!
sentdex
13 Basic PHP Tutorial 13: Multi-dimensional Array
Basic PHP Tutorial 13: Multi-dimensional Array
sentdex
14 Basic PHP Tutorial 15: Functions and Global Variables
Basic PHP Tutorial 15: Functions and Global Variables
sentdex
15 Basic PHP Tutorial 12: Associative Array
Basic PHP Tutorial 12: Associative Array
sentdex
16 Basic PHP Tutorial 14: Foreach loop
Basic PHP Tutorial 14: Foreach loop
sentdex
17 Basic PHP Tutorial 16: Include and Require
Basic PHP Tutorial 16: Include and Require
sentdex
18 Basic PHP Tutorial 7: Assignment, comparison and Logical operators
Basic PHP Tutorial 7: Assignment, comparison and Logical operators
sentdex
19 Basic PHP Tutorial 4: Variables and Comments
Basic PHP Tutorial 4: Variables and Comments
sentdex
20 Basic PHP Tutorial 11: Arrays part 1, basic array
Basic PHP Tutorial 11: Arrays part 1, basic array
sentdex
21 Basic PHP Tutorial 6: If else and else if conditionals cont'd
Basic PHP Tutorial 6: If else and else if conditionals cont'd
sentdex
22 Basic PHP Tutorial 1: Intro to PHP
Basic PHP Tutorial 1: Intro to PHP
sentdex
23 Basic PHP Tutorial 3: HTML with PHP
Basic PHP Tutorial 3: HTML with PHP
sentdex
24 Basic PHP Tutorial 9: While Loop
Basic PHP Tutorial 9: While Loop
sentdex
25 Basic PHP Tutorial 10: Switch Statement
Basic PHP Tutorial 10: Switch Statement
sentdex
26 Basic PHP Tutorial 2: Print and Echo
Basic PHP Tutorial 2: Print and Echo
sentdex
27 Basic PHP Tutorial 5: If else and else if conditional statements
Basic PHP Tutorial 5: If else and else if conditional statements
sentdex
28 Basic PHP Tutorial 8: Arithmatic Operators: Doing math with php
Basic PHP Tutorial 8: Arithmatic Operators: Doing math with php
sentdex
29 Basic PHP Tutorial 17: User Input Form Example / String Manipulation
Basic PHP Tutorial 17: User Input Form Example / String Manipulation
sentdex
30 Basic PHP Tutorial 18: HTML Entities and forms cont'd
Basic PHP Tutorial 18: HTML Entities and forms cont'd
sentdex
31 Basic PHP Tutorial 19: Finding words in strings
Basic PHP Tutorial 19: Finding words in strings
sentdex
32 Basic PHP Programming Tutorial 20: Saving to a File / writing and appending
Basic PHP Programming Tutorial 20: Saving to a File / writing and appending
sentdex
33 Basic PHP Programming Tutorial 22: Hashing part 2: salting
Basic PHP Programming Tutorial 22: Hashing part 2: salting
sentdex
34 Basic PHP Programming Tutorial 23: Variables in Strings and tokenizing
Basic PHP Programming Tutorial 23: Variables in Strings and tokenizing
sentdex
35 Basic PHP Programming Tutorial 21: MD5 Hashing For Security
Basic PHP Programming Tutorial 21: MD5 Hashing For Security
sentdex
36 Basic PHP Programming Tutorial 24: String similarity
Basic PHP Programming Tutorial 24: String similarity
sentdex
37 Basic PHP Programming Tutorial 25: Time and Time stamps
Basic PHP Programming Tutorial 25: Time and Time stamps
sentdex
38 Basic PHP Programming Tutorial 26: Die and Exit
Basic PHP Programming Tutorial 26: Die and Exit
sentdex
39 Basic PHP Programming Tutorial 27: MySQL Databases Part 1
Basic PHP Programming Tutorial 27: MySQL Databases Part 1
sentdex
40 Basic PHP Programming Tutorial 28: MySQL Database Part 2: Reading From Database
Basic PHP Programming Tutorial 28: MySQL Database Part 2: Reading From Database
sentdex
41 Basic PHP Programming Tutorial 29: MySQL Database Part 3: Inputting Data
Basic PHP Programming Tutorial 29: MySQL Database Part 3: Inputting Data
sentdex
42 Basic PHP Programming Tutorial 30: MySQL database in Use
Basic PHP Programming Tutorial 30: MySQL database in Use
sentdex
43 Django Tutorial Web Development with Python Part 1: Installing Django
Django Tutorial Web Development with Python Part 1: Installing Django
sentdex
44 Python Tutorial: File Deletion and Folder Deletion / directory deletion
Python Tutorial: File Deletion and Folder Deletion / directory deletion
sentdex
45 Python Tutorial: How to Rename Files and Move Files with Python
Python Tutorial: How to Rename Files and Move Files with Python
sentdex
46 3D Graphs in Matplotlib for Python: Basic 3D Line
3D Graphs in Matplotlib for Python: Basic 3D Line
sentdex
47 3D Plotting in Matplotlib for Python: 3D Scatter Plot
3D Plotting in Matplotlib for Python: 3D Scatter Plot
sentdex
48 3D Charts in Matplotlib for Python: Multiple datasets scatter plot
3D Charts in Matplotlib for Python: Multiple datasets scatter plot
sentdex
49 Sikuli Tutorial 1: Visually programming in python!
Sikuli Tutorial 1: Visually programming in python!
sentdex
50 Sikuli Tutorial 2: Program visually in python!
Sikuli Tutorial 2: Program visually in python!
sentdex
51 Sikuli Tutorial 3: Program visually in python!
Sikuli Tutorial 3: Program visually in python!
sentdex
52 3D Bar Charts in Python and Matplotlib
3D Bar Charts in Python and Matplotlib
sentdex
53 3D Plane wire frame Graph Chart in Python
3D Plane wire frame Graph Chart in Python
sentdex
54 Raspberry Pi Part 1 Introduction
Raspberry Pi Part 1 Introduction
sentdex
55 Raspberry Pi Part 8: First Download and Update! (Firmware)
Raspberry Pi Part 8: First Download and Update! (Firmware)
sentdex
56 Raspberry Pi Part 10: How to set up a Linux Web Server on your Pi
Raspberry Pi Part 10: How to set up a Linux Web Server on your Pi
sentdex
57 Raspberry Pi Part 11: Remote Desktop
Raspberry Pi Part 11: Remote Desktop
sentdex
58 Twitter Analysis: How to rank a user's influence
Twitter Analysis: How to rank a user's influence
sentdex
59 GPIO Tutorial for Pi Part 2 - Programming the GPIO
GPIO Tutorial for Pi Part 2 - Programming the GPIO
sentdex
60 GPIO Tutorial for Raspberry Pi Part 1 - Setting up
GPIO Tutorial for Raspberry Pi Part 1 - Setting up
sentdex

This video teaches how to create buttons in PyGame using Python 3, covering the basics of drawing rectangles and adding text and interactivity to create a simple button illusion. The tutorial is part of a larger series on game development with PyGame.

Key Takeaways
  1. Define colors for the buttons
  2. Draw rectangles for the buttons
  3. Add text to the buttons
  4. Make the buttons interactive
  5. Add functionality to the buttons
💡 Graphical user interfaces, such as buttons, are illusions created by combining basic programming elements, like rectangles and text, to create an interactive experience for users.

Related Reads

📰
VaultSort REVIEW AI-Powered File Organization and Secure Storage Management for Mac
Learn how VaultSort uses AI to organize and secure Mac files, and why it matters for productivity and security
Medium · Machine Learning
📰
Build a Self-Improving Second Brain on Oracle AI Database
Learn to build a self-improving second brain on Oracle AI Database to enhance your productivity and knowledge management
Dev.to · Anya Summers
📰
The Circuit Boards Keeping the New Space Race Alive
Learn how circuit boards are designed to survive in space for a decade without maintenance, a crucial aspect of the new space race
Medium · AI
📰
DeepSeek: The Good, The Bad, and The Bounty 🧠💸
Learn about DeepSeek, a community issue tracker, and its potential impact on AI development and collaboration
Dev.to · Daniel Ioni
Up next
This AI Books Appointments AND Gets 5-Star Reviews Automatically (I'll Show You How)
Kevin Farugia AI Automation
Watch →