Let's code a TIC TAC TOE game in python! ⭕

  Рет қаралды 150,445

Bro Code

Bro Code

Күн бұрын

Пікірлер: 176
@BroCodez
@BroCodez 3 жыл бұрын
# ******************************************************** # Python Tic Tac Toe game # ******************************************************** from tkinter import * import random def next_turn(row, column): global player if buttons[row][column]['text'] == "" and check_winner() is False: if player == players[0]: buttons[row][column]['text'] = player if check_winner() is False: player = players[1] label.config(text=(players[1]+" turn")) elif check_winner() is True: label.config(text=(players[0]+" wins")) elif check_winner() == "Tie": label.config(text="Tie!") else: buttons[row][column]['text'] = player if check_winner() is False: player = players[0] label.config(text=(players[0]+" turn")) elif check_winner() is True: label.config(text=(players[1]+" wins")) elif check_winner() == "Tie": label.config(text="Tie!") def check_winner(): for row in range(3): if buttons[row][0]['text'] == buttons[row][1]['text'] == buttons[row][2]['text'] != "": buttons[row][0].config(bg="green") buttons[row][1].config(bg="green") buttons[row][2].config(bg="green") return True for column in range(3): if buttons[0][column]['text'] == buttons[1][column]['text'] == buttons[2][column]['text'] != "": buttons[0][column].config(bg="green") buttons[1][column].config(bg="green") buttons[2][column].config(bg="green") return True if buttons[0][0]['text'] == buttons[1][1]['text'] == buttons[2][2]['text'] != "": buttons[0][0].config(bg="green") buttons[1][1].config(bg="green") buttons[2][2].config(bg="green") return True elif buttons[0][2]['text'] == buttons[1][1]['text'] == buttons[2][0]['text'] != "": buttons[0][2].config(bg="green") buttons[1][1].config(bg="green") buttons[2][0].config(bg="green") return True elif empty_spaces() is False: for row in range(3): for column in range(3): buttons[row][column].config(bg="yellow") return "Tie" else: return False def empty_spaces(): spaces = 9 for row in range(3): for column in range(3): if buttons[row][column]['text'] != "": spaces -= 1 if spaces == 0: return False else: return True def new_game(): global player player = random.choice(players) label.config(text=player+" turn") for row in range(3): for column in range(3): buttons[row][column].config(text="",bg="#F0F0F0") window = Tk() window.title("Tic-Tac-Toe") players = ["x","o"] player = random.choice(players) buttons = [[0,0,0], [0,0,0], [0,0,0]] label = Label(text=player + " turn", font=('consolas',40)) label.pack(side="top") reset_button = Button(text="restart", font=('consolas',20), command=new_game) reset_button.pack(side="top") frame = Frame(window) frame.pack() for row in range(3): for column in range(3): buttons[row][column] = Button(frame, text="",font=('consolas',40), width=5, height=2, command= lambda row=row, column=column: next_turn(row,column)) buttons[row][column].grid(row=row,column=column) window.mainloop() # ********************************************************
@Alex-ur3vt
@Alex-ur3vt 3 жыл бұрын
epic video bro
@hackerstech4025
@hackerstech4025 3 жыл бұрын
Love you
@aabaloch1801
@aabaloch1801 3 жыл бұрын
@Bro code how do we save the data of the wins
@rockyelk169
@rockyelk169 Жыл бұрын
@@aabaloch1801 hey man not sure if you are still in need of this but you can use the command "global"
@S_M_HABIBUR_RAHMAN
@S_M_HABIBUR_RAHMAN Жыл бұрын
Op video bro code
@adaboykrisiboy36
@adaboykrisiboy36 2 жыл бұрын
Bro you just explained tic tac toe in 21 min to a complete beginner. Hats off! mate
@TechnoFlash-v6b
@TechnoFlash-v6b Жыл бұрын
dude you have the same profile pic like me
@masoodrezaei5999
@masoodrezaei5999 6 ай бұрын
My first Python project , Thanks a lot.
@saifsyed590
@saifsyed590 3 жыл бұрын
Outstanding explanation given by you bro, easy to understand. And have successfully made this TicTacToe game. Thanks to you again... (HOPE TO SEE MORE AMAZING VIDEOS FROM YOU)
@rafailivanov814
@rafailivanov814 2 жыл бұрын
Very entertaining and also quite understandable. Quality content! Keep it up!
@amenkalai8442
@amenkalai8442 Жыл бұрын
wow very interesting and educative thank you
@monwil3296
@monwil3296 3 жыл бұрын
Hyo Bro ❤️💯. We do appreciate your hard work. Young programmers are building their mental Database thanks to you 👏👏👏👏
@tubacego6893
@tubacego6893 9 ай бұрын
I love this channel it helps me so much learning python and other stuff
@kevinka9670
@kevinka9670 3 жыл бұрын
nice work. Truly inspirational, keep up the good work
@celestinkembe3331
@celestinkembe3331 2 жыл бұрын
I really like the way you explained : Simple, clean and beautiful.
@davidbandini3484
@davidbandini3484 2 жыл бұрын
Thank you so much for the video
@jainendrarout8167
@jainendrarout8167 2 жыл бұрын
Bro Code thanks You are a great man I know I am late but you just made my carrier! I am really happy to get this course for free and not paying that stupid 199$ for python course now I can really apply for jobs but of-course after some practice
@navyadesai67
@navyadesai67 Жыл бұрын
Wow! You actually encouraged me to do python even when I was not that into it❤ Also got a lot of videos left to go!
@bishnudeyvivekanonda7028
@bishnudeyvivekanonda7028 Жыл бұрын
Rad vid bro! Keep up the cool work. :)
@K-tf5ph
@K-tf5ph 2 жыл бұрын
Thanks my dear Bro 💯👑 Could you also do the minesweeper?
@nickarkhipov3684
@nickarkhipov3684 Жыл бұрын
Thank you so much Bro Code! I learned so much new information from this tutorial!
@cherishkansara7851
@cherishkansara7851 Жыл бұрын
I am a fellow bro from now on ❤
@vtWub
@vtWub Жыл бұрын
Great video, very easy to go with and I understood most of what went over, and just searched whatever I didn't know. But 1 question, I am currently using pycharm on my macbook and everything works except the part where it could show the winner, meaning the background does not change to green, or yellow when a tie. Is there a reason to why this is happening, and if there is a work around to this?
@eduardodelgado3973
@eduardodelgado3973 2 жыл бұрын
Excelent explanation, thank you.
@LevitateTheCore
@LevitateTheCore Жыл бұрын
Bro, you're a such great and benevolent programmer!!! God good you are!!!
@hbngamer5776
@hbngamer5776 6 ай бұрын
Good video taught me alot!
@davidcalebpaterson7101
@davidcalebpaterson7101 3 жыл бұрын
only missing the computer player AI trying to win against us. or alternatively adding 2 different controller inputs like mouse and keyboard for each player. example one key to chose which button position and Enter to push it, the the mouse thing will remain the same. I will try to implement this myself.
@shafialanower3820
@shafialanower3820 3 жыл бұрын
How did it go? You figured it out?
@luxury8884
@luxury8884 Жыл бұрын
thx for the game Bro Code always the best ;)
@t34bravo
@t34bravo 9 ай бұрын
This is an awesome tutorial. Thanks!
@MunibAhmad-f5f
@MunibAhmad-f5f 11 ай бұрын
Thank You! Explained well
@yos5770
@yos5770 2 жыл бұрын
you re very good teacher thanks a lot 👏👏😘
@oops5752
@oops5752 3 ай бұрын
Thanks, bro code. I really appreciate it.
@amadeo5813
@amadeo5813 Жыл бұрын
Hello, What can I do to make the squares stay painted when I hover the mouse over them?
@deejaykabwoy44
@deejaykabwoy44 3 жыл бұрын
We appreciate
@vescle2
@vescle2 3 ай бұрын
I can't thank you enough you are the best :)
@isagovfx
@isagovfx 2 жыл бұрын
im on mac using sublime but i cant seem to figure out why the bg colors arent appearing for me. i get no errors however i get no colors froms the inning or ties
@yatinkundra
@yatinkundra 10 ай бұрын
from tkmacosx import Button as BT use this and then replace Button with BT
@jaimeescoto2009
@jaimeescoto2009 2 жыл бұрын
bro very excellent video, but just one question if I wanted to play against the machine, what function can I use
@imadiman528
@imadiman528 Жыл бұрын
Thanks a bunch you're great 👏
@ТимаКазах-ч7о
@ТимаКазах-ч7о 3 жыл бұрын
you are best!!!
@Hema_99
@Hema_99 2 жыл бұрын
Hi, thanks for the video, it really helped so thank you so much for that and also I have a doubt, what platform should I use if I want to convert this script into a mobile application.
@AaronProgZ
@AaronProgZ Жыл бұрын
Thanks for making this video!
@saifulislamishad1222
@saifulislamishad1222 3 жыл бұрын
Big fan 🖤
@hassanfiras3225
@hassanfiras3225 Жыл бұрын
a real great tutorial ty bro
@panoskoutsogiannis799
@panoskoutsogiannis799 Жыл бұрын
very nice video!!
@kapibara2440
@kapibara2440 4 ай бұрын
Great!!!
@obiarne
@obiarne 11 ай бұрын
Very nice tutorial, but is there a way to add CSS to this project? I'm more familiar with that language for styling of the buttons, background color etc. compared to (bg = "orange")
@Friday_42
@Friday_42 2 жыл бұрын
I couldn't get this to work. Very curious, I wonder what went wrong?
@kanime9535
@kanime9535 Жыл бұрын
Thank you for the video bro!
@d.ashley879
@d.ashley879 2 жыл бұрын
Fantastic video!
@krakenzback7971
@krakenzback7971 2 жыл бұрын
great video
@sirikondavenkat5541
@sirikondavenkat5541 3 жыл бұрын
This is Awsome!
@Nothing..
@Nothing.. 3 жыл бұрын
Thank you bro about this good video (:
@oceangamer7875
@oceangamer7875 8 ай бұрын
winner winner chicken dinner
@IntroVids
@IntroVids 27 күн бұрын
Dude just saved my grade for tomorrow😭
@aijounohankyou
@aijounohankyou Жыл бұрын
thank you very much
@hackerstech4025
@hackerstech4025 3 жыл бұрын
😍 you
@alirezasohrab-m9k
@alirezasohrab-m9k Жыл бұрын
this helped me thank you :)
@muhammadkarangwa
@muhammadkarangwa 5 ай бұрын
learning new staff every day from bro code
@ipsxofficial
@ipsxofficial 7 ай бұрын
Cool
@THEMINECRAFTFOXSLEEP
@THEMINECRAFTFOXSLEEP Жыл бұрын
Woah! That’s good video😂😂😂
@Ehsan.Amirii
@Ehsan.Amirii 2 жыл бұрын
great
@Shadoww0
@Shadoww0 Жыл бұрын
thank you for the vid
@GarnetTheif
@GarnetTheif Жыл бұрын
awesome he's a great teacher
@eddyedutz
@eddyedutz 2 жыл бұрын
I see some guys around trying to implement AIs already and here I come with the question to pass the exam lol: How can I add a score to this? I've managed to add a label for the score and I assume I need some variables where we would need to add the wins. Can someone drop a comment if you figured it out?
@Philocalyleena
@Philocalyleena 2 жыл бұрын
Thank you so much sir.
@edwardplayzzz2675
@edwardplayzzz2675 8 ай бұрын
is it different for mac? colours are not changing after win
@imslim85
@imslim85 Жыл бұрын
Thank you very much !
@tips9296
@tips9296 2 жыл бұрын
nice
@WooGad0Xo
@WooGad0Xo 3 жыл бұрын
when this : buttons[row][column]["text"] i know [row][column] get row and column but what is ["text"] does?
@braek2766
@braek2766 3 жыл бұрын
calls all the text from the button.
@souravsarkar6107
@souravsarkar6107 3 жыл бұрын
learn new thing thank you
@logeshwaran3016
@logeshwaran3016 3 жыл бұрын
Hello bro
@randomeditsboy
@randomeditsboy Ай бұрын
How do I make the same project with classes?
@erinasyasya947
@erinasyasya947 Жыл бұрын
could you please show how to the scoring? i’ve tried since two days ago and still wrong.
@shahzodsayfiddinov9510
@shahzodsayfiddinov9510 3 жыл бұрын
Thank you Bro!
@ianbarddal7294
@ianbarddal7294 6 ай бұрын
You're a true CHAD!
@ee-vi9xs
@ee-vi9xs 2 жыл бұрын
nice and gg
@רוןהודיהסלע
@רוןהודיהסלע Жыл бұрын
I like this video, a very good tutorial, thanks.😄 why in this line "reset_button = Button(text="restart",font=('Aharoni',20),command=new_game)" you didn't put () after new_game?
@Karim-zu7zg
@Karim-zu7zg Жыл бұрын
You dont need too
@MishaZib86
@MishaZib86 Жыл бұрын
I used () as in video, and function "new game" didn't work.... but when removed it, all is perfect!
@samadshead6069
@samadshead6069 2 жыл бұрын
hi ive copied the code from the comments but the buttons don't change colour when I run it. its worth noting I'm using a Mac. anyone know why this is?
@mythyfox
@mythyfox 10 ай бұрын
THX SO MUCH
@oMqngo
@oMqngo 2 жыл бұрын
What if i want it to be solo and multiplayer (so you can press a button to choose if you want to play against someone or against the comuter) how would you do that?
@vythir4245
@vythir4245 2 жыл бұрын
You would need an AI for that, which would be even harder to code than the game itself...
@S_M_HABIBUR_RAHMAN
@S_M_HABIBUR_RAHMAN Жыл бұрын
Op video bro code please relply
@bisakhabandyopadhyay5003
@bisakhabandyopadhyay5003 9 ай бұрын
No offense but, whenever I tried coding the game, I ran it to test and the top where it says like, “x turn”, it does not have a space and it is not changing to, “o”. Which is why I had to delete the whole program.😔😔😔
@sidtheepic1103
@sidtheepic1103 8 ай бұрын
Can someone explain the for loops in this. I understood everything except the for loops😅😅
@beldindragon
@beldindragon 2 жыл бұрын
Didn't understand what the lambda command did, can you explain it quickly?
@arshiaa104
@arshiaa104 2 жыл бұрын
good old days when bro was 21 years old
@jorgesingle
@jorgesingle 10 ай бұрын
Great video! but I have a question, I don't know why when is time for "o" to play and I select a button to put it and is not working only with "x". Does anyone know why?
@sjthedarkcreation9744
@sjthedarkcreation9744 2 жыл бұрын
Thanks sir
@DisturbeD802
@DisturbeD802 2 жыл бұрын
If it took you 100 lines of code , i will do it in 300 lines and still have bugs in it and finish it in a month
@mirshodoripov1035
@mirshodoripov1035 2 жыл бұрын
Thank you bro
@akshayak5466
@akshayak5466 Жыл бұрын
bro you are genius
@Just_MMAFight
@Just_MMAFight Жыл бұрын
11:46
@albatrozeditz
@albatrozeditz Жыл бұрын
thank you
@simonan4823
@simonan4823 8 ай бұрын
Error comes up and buttons[][].config does not work at all. any help?
@stewartk5952
@stewartk5952 3 жыл бұрын
what is your coding app
@عَلِيّحُسَيْن-د4ق3ي
@عَلِيّحُسَيْن-د4ق3ي 3 жыл бұрын
PyCharm community
@stewartk5952
@stewartk5952 3 жыл бұрын
@@عَلِيّحُسَيْن-د4ق3ي thx
@Shadoww0
@Shadoww0 Жыл бұрын
bro can you explain why buttons is declared this way buttons=[ [0,0,0], [0,0,0], [0,0,0] ]
@Unenough_cabin
@Unenough_cabin Жыл бұрын
So, that it is easy to read for US I think
@anjalivarthyavath163
@anjalivarthyavath163 11 ай бұрын
At 15:08 it wasn't the output for me... I've tried 4 times...plz help me
@tomba2
@tomba2 6 ай бұрын
did you put a () at the end of pack "frame = Frame(window) Cause that's what I didnt do
@skittle6135
@skittle6135 3 жыл бұрын
Guys I really need help, when I get three in a row vertically it doesn’t say I won????
@Amir_Plays_non_stop
@Amir_Plays_non_stop 3 жыл бұрын
1 more video to finish
@murilosilvestre7736
@murilosilvestre7736 3 жыл бұрын
great job, bro, thank you!
@ccelsiuss482
@ccelsiuss482 2 жыл бұрын
underrated af
@sportfreund-ub2mz
@sportfreund-ub2mz Жыл бұрын
Is it possible to get a copy of your tic-tac-toe-python-code?
@gorgustus
@gorgustus Жыл бұрын
check description and pinned comment
@christiandavequimno7308
@christiandavequimno7308 Ай бұрын
Can’t run error from First character
@rajeevkumarjha8748
@rajeevkumarjha8748 6 ай бұрын
genius
@ashakunjumon4751
@ashakunjumon4751 Жыл бұрын
when i run this and there is a tie the tie thing doesnt work
@anitarawat663
@anitarawat663 9 ай бұрын
Bro my new_game() showing error: AttributeError: int object has no attribute 'config'.
Let's code a SNAKE GAME in python! 🐍
33:06
Bro Code
Рет қаралды 680 М.
Python calculator app 🖩
15:08
Bro Code
Рет қаралды 82 М.
Don’t Choose The Wrong Box 😱
00:41
Topper Guild
Рет қаралды 62 МЛН
黑天使只对C罗有感觉#short #angel #clown
00:39
Super Beauty team
Рет қаралды 36 МЛН
小丑教训坏蛋 #小丑 #天使 #shorts
00:49
好人小丑
Рет қаралды 54 МЛН
Minimax Algorithm for Tic Tac Toe (Coding Challenge 154)
26:33
The Coding Train
Рет қаралды 824 М.
2 YEARS of PYTHON Game Development in 5 Minutes!
4:54
Coding With Russ
Рет қаралды 989 М.
ROCK PAPER SCISSORS game in Python 🗿
9:29
Bro Code
Рет қаралды 143 М.
Let's code a HANGMAN GAME in Python! 🕺
25:07
Bro Code
Рет қаралды 22 М.
Python TIC TAC TOE Tutorial | Beginner Friendly Tutorial
25:15
Code Coach
Рет қаралды 212 М.
Code Tic Tac Toe in Python
33:28
Kenny Yip Coding
Рет қаралды 19 М.
Make Tic Tac Toe in PYTHON and PYGAME! (14 MINS)
14:31
baraltech
Рет қаралды 16 М.
The Dome Paradox: A Loophole in Newton's Laws
22:59
Up and Atom
Рет қаралды 998 М.