 Right, so hey guys and welcome back to another piping tutorial. So as promised in this tutorial I'll be showing you guys how to actually create the gooey version of the Rock Paper Scissors game that we created in the last tutorial. So I thought it was going to be a lot harder But turns out it's a lot easier. So without further ado, let's begin. First off I'm going to go into visual studio code like always and then we're going to go in there and create a new file So control n and we're going to save this file as rps gooey 2 because I've got another file in there which I was playing around with earlier.py because it is a Python file. Now make sure I'm saving this to this desktop right here, and then I'll save it. Cool Once you have your file all saved up, what you want to do next is we're going to be working on a few imports So we're going to need import random to allow the computer to make random choices on either Rock Paper or Scissors and we're going to be needing to import All the stuff from Tecinta just to make life a lot easier So Tecinta is going to help us deal with all the graphic stuff. First off We're going to create our master screen, which we're going to assign to TK. So I'm going to call this Main screen We're only going to have one screen in this game anyway So if I run this quickly just to show you how it works It's going to pop up with a little window But before that we need to make sure we're putting it in a main loop So master.main loop make sure that it doesn't shut off straight away. Otherwise, we don't even see it Cool. So as you see right here, that's what it does. Now, let's give it a title master.title and we're going to give it a title of RPS because Rock Paper Scissors So if you guys are not familiar with a lot of Tecinta, I'm going to be listing a series in the description We're just going to be a little playlist for beginners to intermediate programmers in Tecinta So it's going to help you learn Tecinta a lot better and then you can come back to this tutorial If you already know what you're doing then carry on So now I'm going to create a section for the labels Which is pretty much a widget in Tecinta that pretty much lets us put some text to the screen So my first label is going to be on my master because that's where I want to place it I'm going to give it some text. I'm going to call it rock paper Scissors give it some space as well. I'm not sure why I didn't leave space there, but it's okay I'm going to do font which is another attribute that you can assign equals brackets Speechmarks and Calibri. Feel free to use whichever font you like. I'm going to go with a font size of 14 And now finally I'm going to place it on a grid. So using grid I can place it on row 0 and Then I can say sticky Equals north which pretty much means I want it to the center of the screen adding y equals 10 Which means I want it to be 10 units Space from the top and 10 units space from the bottom and then give it a padding X of 20 Which means I mean 200 actually which means I want it to be that wide So if I run it now, we're going to have a wider window than we had earlier So the padding X gives it the 100 units on the left and 100 units on the right to put it right in the center Cool. So we have our heading and a basic GUI application I mean it's not even an application so far, but hey, it's something to start with Now since we've got that we're going to need a few more labels, which is what I'm going to be copying and pasting So I'm going to copy and paste the Same line again, and then in the next line, I'm going to change the text to Because we're going to be giving the users options of course to select from rock paper scissors I'm going to change the font size to 12 because this is like a subheading The role obviously changes to two if I can type I mean a row changes to one because we've got zero and then sticky equals north the padding We don't really need so let's run this quickly just to show you how it looks and Voila, we have a sub padding which says select an option now good progress so far I'm going to copy this line 10 and we're going to probably going to have to paste it again But before that the next label that we're creating needs to be assigned to a variable So I'm going to explain more about that later So we're going to have a player score label, which is going to be assigned to a label What happened there? Okay, for some reason it doesn't let me so I'm just going to copy it like this and then paste it, okay cool So we are going to be assigning this label to player score variable right here And then the dot grid we need to capture that control X hold on to it for a moment And in here the text is going to be Let's say player Zero because obviously the game is going to start with the player being at score zero Then I'm going to do next line and player score label and then paste my dot grid statement That I had cut before so dot grid row equals to this time because obviously we need to increase the row each time You go and sticky equals west So let's place that on the west. Let's run this again And as you see right here, we have a little label saying player and score equals zero sticky equals West puts it on the proper left of the screen We're going to put the computer score label on the very right. So we're going to sticky equals east So I'm going to copy and paste these two lines right here to do the computer score label as well So I'm going to change player score label to Computer score label Because if you have a player score, we need a computer score as well Now the row is going to stay the same because we're just going to change the direction in which it's placed So in wet in sticky equals west is on the left and now it's going to be on the right because we're going to use sticky equals east Cool. So now that we're done with that. We're going to go ahead and change the text from player equals zero to computer equals zero Now let's run this quickly and as you see we have a neat looking gooey right here The way we have the player score zero and computer score zero on the right Cool. So now that we've got that sorted as well Let's go ahead and create a label for the player choice This label is going to show the user what choice they made so player choice label Equals and once again we are in the copy and paste business. So we might as well do it again I'm going to paste the whole thing again since I've already explained it and in the player choice label We do not need any text. We're just going to leave it blank because we don't know what the Clear is going to choose by default. We're going to find out based on what the player chooses later So all we need to do is master and then the font If you want that to you don't need to mention the font. It's up to you I just like to have a font in there. So I'm going to do player choice label I mean choice not score Choice label dot grid and now it's time to place this stuff So player choice label is going to be on a grid where row equals three because the last one we did was two and then sticky It equals east. Oh, what did I do that? Oh equals three, sticky equals east. Cool. Now just like we have a player choice label We also need to know what the computer chose. So we're going to paste player choice label and its placement and we're going to change player to computer Now we're going to leave this blank obviously because we're going to configure it later and add the text once the user and Computer has made their choice. It will make sense a bit more later in this tutorial Now the row is still going to be the same and then we're going to change it to be placed on the west cool So I've got that as well Actually, we've done this should be west my bad west on the player choice label and East on the computer choice label So I've gone ahead and changed the positioning of the player choice label to west and computer choice label to east Because that's just how it is from before just to carry on with the way it's been Cool now We also need another label to actually declare the outcome of the game So whether it was a win or whether it was a lose whatever it is. We can do outcome label equals label master front equals Calibri and comma 12 Now we're going to do outcome label grid and we're going to place it on row equals three comma sticky equals north So it's still on the same row, but this is going to be in the sensor So the computer choice. I mean the player choice is going to be placed on the left The outcome is going to be placed in the middle and the computer choice is going to place on the right So fair enough That's how it's going to be cool And they're not going to have any text to begin with we're going to add it later on dynamically So that's all the labels that we actually need now. Let's go ahead and add our buttons So if you guys notice as I'm going I'm pushing this master dot main loop line at the bottom So this is going to be the last line that needs to exist in your code if any if you put it anywhere in the middle It's not gonna work properly. It's gonna crash So my next thing is gonna be creating the buttons So the buttons are going to allow the user to select between wallpaper or scissors So I'm going to place my first button on the screen same master and then text equals rock I'm gonna also change my width of the buttons to about 15. Let's say 15 and then command equals we're gonna have to use lambda here. The reason why is We are going to have a function that pretty much inherits the Whatever this button value is so the value that this Button is gonna pass to our function is going to be rock So our function is going to be called I'll come handler We obviously haven't made it yet But we're gonna make it in a second and then in the function We're gonna pass in rock because this is the rock button. So we need to pass in the rock button Cool. Now since that's sorted. I'm gonna go ahead and save that Now it's giving me a red squeaky line because as I said the function doesn't exist and then I'm gonna do dot grid row equals 4, sticky equals West comma had x equals 5 comma at y equals 5 Cool, let's go ahead and run this And obviously we might have an error because we haven't actually got a command for this So we're probably gonna have an error at the moment. So that's fine We have a rock button though. We're gonna go ahead and do the same for that Two more buttons because we need paper And we need scissors Scissors cool. So rock paper and scissor and we all we need to do is change the Rock from the second one to paper so that our function knows that the user selected paper And then from the third one, we need to change it to scissors So that our function knows our function, which is going to be created in a moment That's outcome handler knows that the user selected scissors I'm going to go ahead and change the sticky equals to north because I want this right in the middle And I'm going to take off the padding x in here. I'm only going to need the padding y Now we're going to go on to the last one the last button and roster remains the same sticky equals east because we want it To be on the right side of the screen We need to add pad x and pad y. So that's fine Cool, let's run this quickly to see how it looks like and we have a decent looking gooey rock paper scissors These are three buttons and the user will click on this button to actually Find out what the outcome is cool Very nice. So now we're going to create the outcome handler in a bit But first off, we're going to create a dummy label to leave some space at the bottom screen Because if I run this now, you'd notice that this bottom of the screen is pretty close to the buttons We're going to create a dummy label to kind of create some space there So the label is going to be Place on master And then dot grid row equals five. They're just kind of creates a blank row for now Cool now have I got okay. I've got my master that I've made loop. I started panicking there for a moment anyway Let's save that and run that to see if it worked and it has as you see It's left a little chin space down here. If you don't like that. It's totally up to you your preference Cool So within 12 minutes actually or 13 minutes we've created the whole gooey for this application Now it's the logic bit that we have to deal with that's a pretty good time actually compared to all the other Tutorials of me. Anyway, the logic bit is not too hard. So we're going to deal with that now So first of all, let me explain every time I click these buttons The outcome handler function is going to be run now if I click rock the outcome function handler will be run And a value of rock will be passed If I click on paper outcome function handler will be run with a value of paper And then the same for scissors as well. So let's go ahead and actually create that function now So to create the function Let's see So I'm going to go up here. Let's just close this I'm going to go up here onto my main screen just before the main screen. I'm going to actually create the function. So functions And then in there I'm going to do deaf outcome handler Which is the function name and then we are going to have in there user choice because that's what's going to be passed by the button Now before we actually go ahead and do anything We need to actually declare the computer score Variables and the player score variable in the start of the scope So how we're going to do that is we're going to create a little section up here for variables before functions. So I'm going to create effect. Um it's going to be for dictionary and bars Now I'm going to call my computer score comp score and then it's going to start off at zero And I'm going to call my player score player score And it's going to start at zero like any other game If you wanted to start to add a different value go ahead and do that Cool And let's go ahead in our outcome handler function And we need to globalize those variables comp score and player score so that they can actually be accessed from up here And it doesn't assume that you want it to be local to this function. Cool. So global comp score and then global player score That's all it's that out now. We're going to be using the actual variables to reassign the score later on And now we need to actually generate a random number like we did in the last tutorial. So random number equals random dot rand int One comma three because we only have three outcomes rock paper or scissor This random number is going to help us make the computer choice between rock paper or scissors so For the computer choice in the last um tutorial to convert the number into an actual choice. I kind of did a A long work method in which I use the function We could actually do a lot shorter do it's a lot shorter by creating in an array. So by creating an array of Let's see outcomes equals array First value is going to be rock second value is going to be paper And my third value is going to be scissors cool So now we have an array with a first value of rock second value of paper and third value of scissors Let's start the um random number Range from zero to two so that it goes zero one two So in this way, we can actually use this number to reference to the part of the array That we're looking for and that way we'll just get the rock paper or scissor straight away without having to use any fof statements. So if I do print outcome uh outcomes Um, then use a square bracket and then random number Each time this button is pressed. We are actually going to be Greeted with a different outcome from the computer Let's run this and now when I run it Uh, I'll come handler is not defined Actually, I think it's the previous errors Cool. So what I'm going to do is going to delete this whole thing because it's giving me previous errors And I'm going to run it again now. Cool. No errors rock and as you see the computer selected rock Paper scissors. Okay. Why is it showing? Okay, actually it is working. So if I click on rock The computer selected paper if I selected paper computer selected paper, let's select paper again This time computer selected scissors. Let's select paper again. This time computer selected scissors again Paper again paper. So as you guys see it is working. So the computer is changing its choice Each time we're clicking on a button. Sometimes it gets stuck on the same choice But that's completely because we have a very small range. We only have three numbers. Cool. So that's that sorted out So we have the computer choice. We can now assign computer choice a new variable equals um outcomes square brackets and then And what was it random number? Range is frozen for a second Cool. So we have computer choice equals outcome number, which means we have the converted outcome from the computer of its selection Now let's go ahead and do some of the magic stuff. So let's go ahead and add um Whatever player choice there is Being made and the computer choice that's being made to the label that we created earlier So if you remember if we go down here, we had a label called player choice, which we didn't add any text to Same with the computer choice where we didn't add any text We're going to be adding that text right here once the selection has been made So we're going to call it with its name. So Let's see player Choice label.config is what we use to add anything to it later Um foreground equals red because why not? Uh, let's just give it color codes, you know text equals Player choice Um, and then we use a plus String we're going to be converting the user choice That's passed through To a string. I mean it's probably already a string, but just in case It's like a fail switch and then we're going to do computer choice label dot config where the foreground equals green the text is going to be Computer choice Hold on plus a string And then computer choice, which we just stored right here just a second ago So now we should be able to get the computer and the user choices. Let's run this rock computer Player chose rock computer chose scissors Paper player chose paper computer chose paper scissors Player chose scissors and computer chose rock. So it's perfectly working Now we need to update the scores as well. That's what we're going to be doing now So to update the scores as you may remember, we created two variables up here comp score and player score So we're going to be using those and updating them as and when we actually win or lose So before we actually go in and do that, we need to know Who won in the competition? So in my previous tutorial, I showed you guys how to use a dictionary to make Implementing this logic a lot easier. So I'm going to go through it again in this tutorial But if you want an in-depth explanation on how to use it I'm going to be linking the two tutorials on dictionaries that I created before So go ahead and watch those if you want a thorough understanding of how it works Cool So now we need to add the dictionary of different outcomes that we can have Now I'm going to actually call this. Um, I don't know Let's just call the schema for now This is sort of like a schema for of different information and outcomes. Cool So now we're going to have in this dictionary key called rock And then we're going to assign the value of the key called rock Then we're going to use a comma And we're going to have a key called paper And we're going to assign the value of paper to Another dictionary and then we're going to have another Key called scissors and we're going to assign the value of the key scissors to an empty dictionary again Perfect. So the now we need to just do a comparison. So rock against rock Will be what score let's say if rock against rock is a draw, obviously We just give it a score of one now rock against paper would obviously be a loss So the score would update to zero Now rock against scissors What would the outcome of that be it will be two because rock would win So on a win we award the user with a score of two on a loss We award the user with a score of zero and on a draw we award the user with a score of one Cool. So just like we did for rock, we're going to find out all the events for paper So what if paper was played against rock? We are going to get a two because paper wins against rock Then what if it was paid against paper? Well, obviously it's going to be one because it's a draw and then paper against scissors is going to be two because obviously Actually, it's going to be zero Well, I don't know what went wrong in my brain there. So paper against scissors obviously paper is going to lose Now last one scissors against rock Will obviously lose then we have scissors against papers, which is going to win And then scissors against scissors, which is going to cause a draw So these are literally all the All the schema that we're going to need. So these are all the events that could actually occur We are avoiding making these of if and else statements because they are jarring and really long to go through So i'm going to show you how to use the schema to actually Find the score and update the player score or computer score based on who won So this is going to be very interesting So put your thinking hats on because we are about to do a bit of a A bit of a confusing one So we are going to go back into our outcome handler function Which is triggered each time the user makes a choice on whether they select rock paper or scissors Now we are going to create a variable called outcome Well, let's just call this result because there's a lot of outcome stuff So result is going to actually find out what the score is So let's do outcome equals Now we are going to use our schema that we just created and then we in our schema We're firstly going to look for the key of user choice And secondly we are going to look for the key Of the computer choice. So what do I mean by that? This is so confusing Cool, let's copy and paste this up here and then explain So when I say result equals schema The first thing that this dictionary or this statement does is it goes ahead and it selects this dictionary called schema Now let's assume the user was to select rock Now if the user selects rock the key is rock and the value is that is returned as this dictionary right here Now once we're in this dictionary, we still have key and values So when when I if the user choice was rock and the computer choice was paper for example Um, then we would land up right here and the value would be zero So rock against paper is obviously a loss. So we get zero. So that's how it works Okay, so it will pretty much work for anything that you enter in there. Cool So I'm going to paste it back where it belongs to Oh, why am I doing that Computer choice cool. So we have our results variable right here and that will pretty much just return If it's a one then we know that it was a draw if it's a zero We know it was a loss and if it was a If it was a two, we know it was a win cool So now we need to do Some if statements just three actually I'm trying to avoid as much as possible, but just three just three so bear with me so I am going to Erase this pigeon bridge that just produced for some reason and then press enter after the labels update for the choice And then type in if outcome equals two Then we need to do Player choice equals player choice Plus two and then we need to do player Equals Uh, actually we need to why did I do choice here? It needs to be player score my bad brain froze So we're updating the player score here So if the outcome was two that pretty much means that the user's choice was against the computer choice wins So if it was two, we know that the computer one if it's a zero that we know then we know that the computer Okay, so if it was two, we know that the user wins But if the if the score was zero, we know the user lost and the computer one So that's the logic we're going with so in this case the computer wins I mean the user wins. So we update the player score And then we are going to also update the player score label. So player score label top config Foreground equals Foreground let's just actually let's just do text equals player colon just like the last one plus string Player score, we have to convert it to a string because it's obviously a text and type So we've got the player score and we need to do outcome label Which is going to show the outcome dot config program equals blue And this is the label that we left blank earlier in the tutorial and then text equals speech marks And then we say player one because obviously if the score is two then the player wins Which means his choice against the computer was good enough Now this outcome. I don't know why I typed an outcome. It's actually result. So if result equals two Then we need to do this stuff, which is updating this player score by two Actually updating the screen to show the most updated version of the player score And then also displaying the outcome of the game. So player wins Now let's go ahead and do the other outcome. So B lift result equals one That just means that was a draw. So what I'm going to do is I'm going to copy and paste these lines right here And then in here, I'm going to leave player score as it is But I'm going to change player score equals player score plus one Then I'm going to copy the line and then paste it again Because we need to update the computer score as well since it's a draw. So both players get one point computer score equals computer score plus one And then we need to update both labels and the outcome as well So this is fine We just got to copy and paste this again Because that's the player score label. We just got to update the computer score label as well. So computer score label.config has changed the player to computer And then we change the string player score to comp score Cool, and then we say outcome draw Now last but not the least we do the event for when the result equals zero, which means the user lost And the computer won in that case cool, so we just do something like We've got to copy and paste the computer stuff. So I'm going to copy and paste the computer score update Computer score equals computer score plus one. Okay, I've got an A logical issue here. So let's go back to line 31 and change comp score equals to comp score plus one instead of player score plus one And this is actually going to be comp score Cool, I seem to be spotting most of the logical errors. That's pretty good So let's update the player score with plus two because if the computer wins It gets a plus two just like the user did and then let's go and update the computer label And the outcome label too. So I'm going to copy those two lines and then paste them down here so computer score label is going to be set to The computer score which is fine and then computer outcome label or the outcome label is going to be set to Computer one cool And that seems to be about it for the logic actually Is there anything I missed out? I don't think so. So let's deal with any errors that we have Hopefully we don't have any so rock And as you see right here, it's working flawlessly, which I'm really happy about With now it says player choice was rock which we selected rock. It's fine Outcome was player one because rock played against scissors. The computer plays scissors. Oh, that's sad Let's go again with the rock and as you see right here, it remains the same Let's go again with rock. Oh, we ran out of luck this time The computer chose paper and paper against rock as you know guys is a win for the computer Let's go ahead and select scissors Now this time it was scissors against rock, which means the computer wins again computer one Scissors again or the computer is cunning you chose the same one again Oh, we finally got a score And that's about it guys if you keep playing it will keep updating your score. I mean, it's infinite right now your challenge for this tutorial would be to actually Program into the logical layer of this function Program a stopper so that once the player score or the computer score reaches. I don't know like 10 You announce the winner of the game. So if player reaches I don't know a score of 10 before the computer then player wins if computer reaches a score of 10 before the player then computer wins And if they both reach the score at the same time, which is very unlikely to happen. It's a draw So yeah, that's your challenge guys. I hope you've enjoyed this tutorial I did enjoy a lot because this was um kind of jumping into intermediate stuff rather than just Slogging around with beginner stuff, which is fine as well But I just wanted to hop in into a bit more intermediate stuff so you guys can learn a bit more I hope you guys have enjoyed. I hope this was actually helpful to you in any way or the other like always this Code is going to be stated in the description so you can go ahead and Download it and change it to your needs, but I recommend watching it through and actually understanding how it works if you guys want to actually support the channel you can do so by purchasing a highlighted message or a Custom emoji forms the super chat during the video premiere I'm not forcing anyone to do so, but if you would like to do it out of gratitude go ahead and do so it really helps out And last thing I wanted to say was guys thanks a lot for all the support that you guys have been showing I really do appreciate it if you guys could keep sharing the videos like you have it would be amazing And I will see your beautiful faces in the next tutorial guys. Peace out