Transcripts
1. Introduction: Hey guys, I'm Joel Del. I'm a software developer. I'll be able to start
for this course, building a Tat game in
Python with Python. The sumpter also learned
from this particular guy, Dem, the guy is very good, can check online for
one of these courses. In this course,
we're going to start with understanding
how the game actually works and then
understanding mode. We are going to be
using the package, the UI packages we are
going to be using. Then we are going to
log fully into building our game in this course
without any delay. And further, let's get
started. Thank you.
2. Project Explanation: Welcome back guys. So, in
this part of Victoria, I'm going to explain how the game is going to look
like for the second. Maybe people that don't
know how Tick played, or maybe you won't
know how it's played. Or we're going to design the interface in
this particular tug, the interface is going to
look exactly like this. We're going to have our option
where the user, either, we're going to put
only one option there, the user can just restart
the game over there. We're going to have nine
boxes in this game. This is how the game
is going to be played. The first, the first player will be X in two is going to be X. The first player
is going to be X, and the second player
is going to be when the first player played X. The second player play when the second player play and click on this
particular button. Because all the box is going to be put in where
we are developing, it may click on this button, we're going to flag an arrow that this particular
box have been taken. Or even click boxes
that belongs to maybe already this
particular box. And X going to click it
again is going to flag an arrow over it is going to be we are going to develop
it and says that in take to when X this particular ship where we say X actually
wins the game. In the case of we
have this particular, she says the game in this sense maybe X is you are standing
beside each other. That maybe we have X clean. This one we have X, in this case we have Xs. X. It's going to be a
form of, if we have x, x, this shape, they say X
actually wins, vice versa. In this case have this particular
times xy X actually. Or in this place, x
actually won the game. Vice versa. Maybe also
let me clean this part. Maybe like this in as much they are in
this form or this form, or this form, or this form, or this form, or this form. Either it's x or it's a win
for either of the side. Either x of this
particular play. Maybe x, x, maybe x x win
for X. Maybe it's a year. Yeah. Yeah, it's going
to be win for who? Maybe it's any other type. So it's going to be win, win for the player. This how the game is
going to look like. See you guys in the Nsttera
when we are going to start our development using
Python. Thank you.
3. Intoduction to Tkinter GUI: Yeah, welcome back guys. I have my game just for game
I've created Python for. I don't want to use a
reserve name in Python. Maybe, I don't know, maybe
there's a reserve name or reserved game in Python. I don't want to use that. I decided to use. As said earlier, we
are going to be using Tinker Python interface
mode in discourse, we're going to be using
Tinker user interface, you can use Pycharm Q five. Tinker is also, you can use V V most times is used
for app development. Let's get started. We are going to create our
interface by using tinker. I don't think you
have to install install Tinker
before you use it. I think it already is
like follow from Python. There are some
packages that used to follow Python
When you install Python on your system,
it's like foo. If we are running it
and it's not working, just go to pip search pink directly to your system
and it's going to work. We're going to call it, we're going to import
everything in this page. This tactually means you're installing everything
from Tina's. Not that you're installing, maybe only message box
or you're installing only you're installing
everything from Tina. Specially installs message box separately. So inside or for some reason you have to
import it like this. If you're familiar with class object related
programming in Python, when you import something you
have to link it or you can just use it directly link
it to a particular name. I'm to call the name
of my instinct class, I'm going to call it
roots equal to take. When you use a think, have to do something like this
so that all modules, all the attribute of Tina is
going to be used by root. Don't mind this
one, visual studio. When you import, when you
use a particular name, it feels like you have to import a library have the same name. What actually import this I
think r is also serve name. We don't need this,
I have to delete it. After that I want to have, I want my interface to have a to title inside the string columns. Call it. This will be the name of it's going to come up in form of Remember we illustrate the paint software that
how it's going to look. The title of the
game is going be, that's going to be the name of the after that I want to have
a on my name to make it, to make it more and more
cool to look alike. I'm going to root when
I'm calling it name of this particular instant
variable instinct for this class I do. Assess all the
attributes so we can see other attributes I can assess from this module. For this particular
Tinker package, I'm going to see root. Can you see icon map
to see what stands for Amp for icon were wam. Return this stop that
you can read this, understand this more often. You can go to the documentation
of this particular mode. Just here, I have a
particular icon here. This is the icon. This icon I want to
use for this course, so I'm just going to
call the name game. Maybe in order for you
don't have this icon here, maybe download or
something can just say it's going to direct back to this
particular icon. What is sometimes more
advisable to just bring it to the program folder and save it there so that I can just
call it as easy as possible. This is it for the last part. We're going to use root. Make this to see this particular outside you're going to use rootlook Can read more
about all this method. I will show you. If you don't
put this main look there, you see what's going to happen. Let me comment it out. Let's see what's
going to happen. Put it so let me my interface
can just pop up of back. It's not going to
stay if we don't add this particular attribute to this main look to it now
that I've add it to it. So let me just run it down. We see our interface. This is our tanker interface. This is our application that
we can put anything here. It can be a sign up page. Anything more fun or anything you want to
use for semi icon here, the icon I use and the
name of the game is already we have
created our interface. In the next tutoria, we're going to start with writing some codes in
which we are going to start to put all the
buttons we need and we're going to create our
click functions. See you guys in
the next tutoria.
4. Creating GUI Buttons: Welcome back guys. In this
part of the tutorial, we're going to move
on by Harding, buttons and x and zero
parts to our code. This particular attributing want to start creating buttons. We declared the
naviable of the button. Can just write the code
a long, just follow me. I'm going to call my first one, it's going to be one
inside the butt. I'm going to, you can see all those things that
I need to add to it. So I'm going to call the name of this particular instinct, the name of this variable
inside of it route, the text that will be
on the bot is going to be empty for
now some reasons. We're going to see the
form that we're going to use equal going to be vertica. I'm not sure of
the spelling ball. Let's just write on the front. Size is going to be 20. The height is the height of the botting is
going to be three. The width of the bot
going to be six. It's now like in form of square, rectangular shape,
but the rectangle is going to be like a
vertical, long rectangle. Really. Let's ride
on the background. Bg, the color of the background
is going to be system, it's going to take
the color of windows, colts something like it's not really gray or
something like that. For Mark, there's another
name you have to put here versus this
particular color for Windows, this is it. After we are going to
go for command command, we want this particular
button to follow. When you click the button, what you are pull, that's
what we mean by command. We're going to be using lambda, lambda, lambda, lambda stuff. We go for this particular
function that will be click click is a function. The function it's
going to accept. Going to accept the
name of this variable. We're going to accept the
name of this variable, B. Don't mind what is
saying, I click. For the sake of this error, our function create a function click, click. But for now, let's just pass. You don't want to do anything, you want to continue code, you just can't
just pass damages. When you see this particular
code, just move on. Don't wait according
to our listing. Nine buttons, 123-456-7789 We just have
only one button now. I'm just going to copy one. I'm just going to copy this
one and change it control. If you're using visual studio
code as my just control D, I'm just going to
put space in it, signify that this Ft and this Luv to move on control VV, I'm just going to change
the name. This will be two, nine, remember here also here. You're going to change it. 8.9 we have successfully
create our botingst's. Run it and see how the
bot actually look like. Maybe we are even doing
directing or we are. Remember where you are
put in the button, all the code you want to
write must be inside this. To anything outside the
zone is not going to. Let's run it and see. So what's not showing? The buttons are showing. Now to resolve that,
there's something called grid in this particular, if you are used to
developing a website also or application development, to understanding grid that's RID grid is like
putting everything in. Each is going to show for this. I say one, great. So you are saying
that put this one into zero, column zero. Column zero. So I'm just
going to copy this. Continue. 56789. Yeah. Yeah. I'm going to change this 123456. I'm going to change where
each of them is going to be. I want all these
one to be in zero. That means 123. Each column one, this column two, this
column three to three, all in they have
different columns. This one is 021 and route two, you'll be wondering why
is No 12 and route three. In programming, our
numbers starts from zero down to nine or infinity. We start from 01, all
of them are in one. This one is going
to be changed to column one, column two. The ones going to change, um, 111.1 to two. Let's check this zone out, maybe is going to work. Now let's run it. Wow, now we have our buttons. We have all our button in
a separate this place. Look at me, the arrow. Let's on it again. Stop this on it again, now we have our puts. Nothing is happening
whether I click this turn to x to zero x, or where is happening when we're going to use
this particular function, this function, we are
going to declare where we first x, where you click this. Turn it to start of pass. I'm going to remove it. I'm going to declare
two variable outside of this function. I'm going to declare
the first variable clicked I want to click
Click is reserved clicked. I'm going to understand
why I'm using this logic and equal to zero. We're going to be using
this two variable back my function click. What happen when we click click? We're going to put one
argument so that, remember But there's a particular
argument inside. For the sake program is
not going to be like wow. We are putting 123 as argument, as parameter to this function. Look, this argument or this particular function
is accepting nothing. We're just going to B a
parameter, this function. Let's write on what should
happen when we're doing this. I'm just going to call the two global variable I. I'm
going to call them global variable to click and what should happen? I'm saying that after I
called the two variable, I'm just going to declare
some conditional. I'm going to use if
statement to do something. This is what I just did, the eight lines of code. I'm saying that in brace, this is the same type of
this one is put here. We are saying that if one text is empty with this bracket, this give me the opportunity to assess anything inside
this, any property of this. But I can change
the, I can change, I can change the
background of this by using this bracket click. These conditions
still remain the same when they click
on this button. X should change to X should change from true to force and counter
should be plus one. What we are doing here is
the first time the user click it is going to be X is going to change
the click to force. The second statement is if
a particular box is empty, another box is
empty and click is, that means X has already
played his own part. The click going to
change the text of the box to, it's
going to change. Click back to true and
going to increase. This is going to continue
from x0x 0x0x0 000x0. This counter means maybe after I'm using the count for maybe the forces are played, x0x 0x0x0, None of them
actually weighs the game. None of them. Neither Xia. The counter will
be equal to nine. We want to end the game by time and want to
restart the game again. That's why I'm
using the variable. You're going to see what if the user actually click on the same button again,
what should happen? So I'm going to say L to
bring out the message box. Message is where we are going
to use our message box, er, er, what should be? The message is going to be
tied to the first U Pm issue, or the argument we should
enter is a form of strength and should be the T. After that we
have the message. I'm going to put
the T. It's going to be after that, I'm going to put the
message selected. This will be the message, it's going to hope for the user. Let's just run this thing and see what we have
been doing so far. Maybe actually
doing the writing, because after writing,
after writing in error, it's going to be okay. Now. First click is a, wow, it's actually working. Can you see what if I click
this same button again? See hey box already selected. The game is working
perfectly well. If you notice, this
is a win game for X. But actually working, this is what we're going
to work on. On the next. We're going to sort out
if win and if wins, See you guys in the next Storia.
5. Check if 'X' won: Yeah, welcome back guys. In this part of the story, we're going to check in, the
passenger wins the game. And we're going to put in some conditions at
which maybe it's X, maybe X is in box 12, box three. That's a wind for x. We are going to be
considering everything in this game if x is
2.3 has win for x. If x is in 14.7 there's
a win if x is in 15.9, does a win if x is
in 25 and x does a win if x is in the 6.9
the wind ex is in 456, ex is 789, there's a win. We are going to be writing
and vice versa, for zero. If zero is in all
those conditions that I put for x, that's a windfall. We're going to
write an statement that we do all those
things for us. It's going to be a
long coding distance. I think the if you
know what to do those parts and move along, pay the video back and continue. We're going to declare
a function function that we do all those
things that will be check if one, this will be the
function that we do that you're not going to accept any attribute
or any parameter, or any argument inside. We're going to declare a
global variable inside. To call the global
variable winner equals false X. Got to start with a
conditional statement. Conditional statement. I told you that if
you want to assess all the attributes
inside this box, um, so if one takes equal, equal to x two, I'm just going to copy two to three equal equal to x. What should happen? We're going to change the color
of those box to green and then print out a message that X wins the game
or stuff like that. S, let's start one configfig. Configure can change color. One BG grand color. I'm going to change it to grain. That's the same thing I'm going
to do for the rest of it. I'm just going to duplicate this one way to it's going to change
the colors to grain. Then after that twin
is going to be true, we're going to have a message box that we give. Remember we want to
put in the name, my dear child message. When other that we are going
to disable all floating. We'll be disabled
table all sorry. Disable both and is also Going to be a
function. We've not declare any function like that. So I'm just going to dust right away and use the
other logic of pass. So it's going to be sorry all well, but now I'm
just going to pass. That's for the first box. That's for the first box is that's what the
box holder is. 123. So we're going
to continue with 456789 and the rest
that is 159149. That's how we're
going to continue. I'm going to declare an LC statement for
the sake of time, I'm just going to copy this. Yeah, this one is going
to be 45.6 so it will be B B 5.6 So I'm going to change it, 45.6 So we are going to continue for nine. I was going to copy this. Duplicate it, sorry. I was going to duplicate
it and changes on to 789. Same to be 78.9 What we are going to do 125-819-8159 Each
one, anyone you like. I'm going to continue
with copy paste it here. So I'm going to do 25, I'm going to do one for seven. I want to complete all the
one for one's going to be 4.7 You can use this trove
replace for this case. I think it's going to be materials because we
have many seven years. It's going to interrupt some
other code and I don't want any changes one back to 11 to four after that condition. So I'm going to move to 258. This one is going to be 25.8 Yeah, 25 and two. And what else else? Let's check 25258. Let's just 369-36-9369 going to be sorry, 369369. What other one zone remain? The 159 next 59959. Yeah, 59 to 159. Gona 159. So does ship in the order 357 to 5.10 same year, 35.7 So I think that's all for So I'm missing
one of it I think. No, I I do 4725869. I don't think there
is only one with 696. No, don't have any 69. Maybe we mistakenly deleted, so let's do that now. Nine, 69. 69. I think we are with all the X. Let's just run it and see
maybe it's going to work. Yeah, it is. 10 x0x0. Oh, it's not working? It's not working? Oh yes, yes, it's
not going to work. And let me check. Yeah, you're going to call the function check e. I'm going to check if one also. Let's see. Now, let me see. Wow, it's not working. Is now perfectly working. Now I can click another thing. We can click another thing. And it's not supposed to be
what this disabled button actually means for the net. We are going to be
working on that, checking all these conditions
we have done for X, um, is actually working for. Also. That will be for the nest. Storia, U in the nest.
6. Check if 'O' won and Tie: Welcome back guys. In
this part we are going to be checking wings. We check X wing. It's still going to be
in the same function. It's going to continue from el. I've done it already on my own. Just going to copy and
to make it easy for you, just copy all the and
change the change the zone to maybe you're using capital
letter, you're using zero. Please indicate it so that
there won't be a narrow you're going to change
all the one to one. Also you're going
to change it to everything because the
conditioner is actually the same. So I'm just going to past
the one I work on on my own. I'm sorry. Okay, that the video
and work on your own. Also collect some box here. Go to just use this, let me copy this and use this. You can also use something
like this for your X. And it's not advisable,
we are not very careful. You made a lot of mis, you're going to make a lot of mistake. I don't like to be changing it. So I change, I don't think there's now I have all these conditions
for X and in my code, so I'm just going to indicate if wins to be this
condition is perfect. Plums have been filled up
and nobody actually wins. When we are going to
make use of that, can we declared the other time? Can't variable declared
this can't be variable. We declared other times when we are going
to make use of it. The other time we
are increasing it, as the players are clicking
the button is going to keep on increasing,
increasing, increasing. We're going to check
if there is a tie, there is a if there is a
tie, what should happen? We are going to declare a
conditional statements. Cut is equal, equal to
nine, equal to four. Still means there's no way
I yet what should happen? Message box, we need our
message show this time. I'm just going to copy this
one for the sake of time, See, show you this another line. I'm just going to say, no one wings going
to pop up like that. I'm going to disable
all the button. I'm going to use
disabled or BTN, BTN. Let's work on our
disabled button so that it is not going to part. It's going to work on
its disabled will be one.com Fig state state of the. So I'm going to configure
out the state of the button. Should be disabled, sorry, going to be disabled. Disabled. The bottom disabled. This is only working for one, so I'm just going to
copy it for 256789, doesn't change ads, the button
is going to be disabled. That's what happened
here was the error. Oh, I'm actually assign
another ten year. It's supposed to be like, I think there's no error Now, let's run it and check
everything maybe is working perfectly now. Let me try and
make to win, okay? Wow. Can you say it's working? I cannot restart again. I just have to cancel
the game at all over. Let me make it a tie that
nobody actually wins. Let me try make
something like that. It's a tie. No one wins. It's actually working. But after this, I suppose
they're supposed to be an option for me
to restart the game. That's what we are
going to work on. On the Nestor, we're
going to create a menu button in which user
can go and reset the game. Tell you guys, Nik you.
7. Final touch Reset: We are likely in the last
part of the tutorial, we want to create a function and a menu that will make the
user to reset the game. That means to restart again. At the bottom of our code, I think it's more
variable to put. It's not going to be
informal function yet, but we are going to call
it function For that. We're just going to create menu. Menu. Menu is a function menu, so I'm going to call
root inside the master. Check a menu accent
for the master. The master of this
thing is route. You remember when we click the route after that
to configure the root rot configure menu menu after that also
create the button at the option inside the menu. It's going to be
option option menu. Option is another option menu
equal to menu inside it. Go to passing my menu and then you can read a lot at the documentation
about the stars. After that, I'm going
to say my menu, I'm going to add
another ten Ski. That'll be label, so I have to pass in the
label inside it. The label is going to be option going to be
a form of string. After that menu
called option menu. After that's passing
option menu, option menu, add command. I want to add the command. This particular option
is going to follow bells going to be reset, reset. And actually a mistake, the set game command
is going to be reset. To be reset, reset is
going to be a function. I'm going to play function, I'm going to declare the reason I'm declaring reset. I don't want decer'mjust going to be writing
all this thing again. That duties and duties. Duties. And I'm just
going to put reset. Yeah, I'm going to put all
these things inside it. All the commands
I'm inside it just I'm going to call a
variable into it. It's going to be one 3456789. It's not like where the
variable I pass them as a variable into it
and also a zest. So after that true declared, the other time zero, I'm declaring it inside
this reset button. So this reset function, the function is going to know, I'm just going to call the function here this form, so that when the game starts going to be
in form of receipt, in form of recept, everything is going to be in
form of recept, can just on with the
code and everything. Let's run this and see
maybe we are making sense. Just take it. Wow, we have the option here. Reset. After doing
all these things, I can just reset my
game and try this. Wow, I don't even know. I can just reset, it. Can just continue. Playgame. Oh, it's X win. After this, I can just reset
A game is so nice and cool. We've finished our game
completion of this thick game. If you want to add
maybe other features to it could play part
of your assessment. Maybe you want to
add scoreboard, maybe an X zero
and actually ten. That means they're
playing like 100, maybe 15 and all of one. You can just, that
will be a function, a menu testing and it will
just be form of score. The name of the dist going to be score and it's
going to be put, increasing the number as
much as Bs X zero is we. Thank you guys for watching this tutorial from the
beginning to this point. I love you guys. Please leave a review
for other people know. Thank you very.