From a034be474fdab0d9d5de4fff46679f4862dcd03f Mon Sep 17 00:00:00 2001 From: Sumit Suman Date: Thu, 21 Oct 2021 08:08:04 +0530 Subject: [PATCH 1/2] Added tic tac toe game, made using python --- Mini_Games/Tic_Tac_Toe.py | 120 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 120 insertions(+) create mode 100644 Mini_Games/Tic_Tac_Toe.py diff --git a/Mini_Games/Tic_Tac_Toe.py b/Mini_Games/Tic_Tac_Toe.py new file mode 100644 index 0000000..172c01a --- /dev/null +++ b/Mini_Games/Tic_Tac_Toe.py @@ -0,0 +1,120 @@ +#########❤❤❤❤❤❤❤❤❤❤❤❤❤##################### +#########Made with ❤ by Sumit Suman##################### +######### Github: @sumit6258 ###################### + +from tkinter import * +import tkinter.messagebox +tk = Tk() +tk.title("Tic Tac Toe") + +pa = StringVar() +playerb = StringVar() +p1 = StringVar() +p2 = StringVar() + +player1_name = Entry(tk, textvariable=p1, bd=5) +player1_name.grid(row=1, column=1, columnspan=8) +player2_name = Entry(tk, textvariable=p2, bd=5) +player2_name.grid(row=2, column=1, columnspan=8) + +bclick = True +flag = 0 + +def disableButton(): + button1.configure(state=DISABLED) + button2.configure(state=DISABLED) + button3.configure(state=DISABLED) + button4.configure(state=DISABLED) + button5.configure(state=DISABLED) + button6.configure(state=DISABLED) + button7.configure(state=DISABLED) + button8.configure(state=DISABLED) + button9.configure(state=DISABLED) + + + +def btnClick(buttons): + global bclick, flag, player2_name, player1_name, playerb, pa + if buttons["text"] == " " and bclick == True: + buttons["text"] = "X" + bclick = False + playerb = p2.get() + " Wins!" + pa = p1.get() + " Wins!" + checkForWin() + flag += 1 + + + elif buttons["text"] == " " and bclick == False: + buttons["text"] = "O" + bclick = True + checkForWin() + flag += 1 + else: + tkinter.messagebox.showinfo("Tic-Tac-Toe", "Button already Clicked!") + +def checkForWin(): + if (button1['text'] == 'X' and button2['text'] == 'X' and button3['text'] == 'X' or + button4['text'] == 'X' and button5['text'] == 'X' and button6['text'] == 'X' or + button7['text'] =='X' and button8['text'] == 'X' and button9['text'] == 'X' or + button1['text'] == 'X' and button5['text'] == 'X' and button9['text'] == 'X' or + button3['text'] == 'X' and button5['text'] == 'X' and button7['text'] == 'X' or + button1['text'] == 'X' and button2['text'] == 'X' and button3['text'] == 'X' or + button1['text'] == 'X' and button4['text'] == 'X' and button7['text'] == 'X' or + button2['text'] == 'X' and button5['text'] == 'X' and button8['text'] == 'X' or + button7['text'] == 'X' and button6['text'] == 'X' and button9['text'] == 'X'): + disableButton() + tkinter.messagebox.showinfo("Tic-Tac-Toe", pa) + + elif(flag == 8): + tkinter.messagebox.showinfo("Tic-Tac-Toe", "It is a Tie") + + elif (button1['text'] == 'O' and button2['text'] == 'O' and button3['text'] == 'O' or + button4['text'] == 'O' and button5['text'] == 'O' and button6['text'] == 'O' or + button7['text'] == 'O' and button8['text'] == 'O' and button9['text'] == 'O' or + button1['text'] == 'O' and button5['text'] == 'O' and button9['text'] == 'O' or + button3['text'] == 'O' and button5['text'] == 'O' and button7['text'] == 'O' or + button1['text'] == 'O' and button2['text'] == 'O' and button3['text'] == 'O' or + button1['text'] == 'O' and button4['text'] == 'O' and button7['text'] == 'O' or + button2['text'] == 'O' and button5['text'] == 'O' and button8['text'] == 'O' or + button7['text'] == 'O' and button6['text'] == 'O' and button9['text'] == 'O'): + disableButton() + tkinter.messagebox.showinfo("Tic-Tac-Toe", playerb) + + +buttons = StringVar() + +label = Label( tk, text="Player 1:", font='Times 20 bold', bg='white', fg='black', height=1, width=8) +label.grid(row=1, column=0) + + +label = Label( tk, text="Player 2:", font='Times 20 bold', bg='white', fg='black', height=1, width=8) +label.grid(row=2, column=0) + +button1 = Button(tk, text=" ", font='Times 20 bold', bg='gray', fg='white', height=4, width=8, command=lambda: btnClick(button1)) +button1.grid(row=3, column=0) + +button2 = Button(tk, text=' ', font='Times 20 bold', bg='gray', fg='white', height=4, width=8, command=lambda: btnClick(button2)) +button2.grid(row=3, column=1) + +button3 = Button(tk, text=' ',font='Times 20 bold', bg='gray', fg='white', height=4, width=8, command=lambda: btnClick(button3)) +button3.grid(row=3, column=2) + +button4 = Button(tk, text=' ', font='Times 20 bold', bg='gray', fg='white', height=4, width=8, command=lambda: btnClick(button4)) +button4.grid(row=4, column=0) + +button5 = Button(tk, text=' ', font='Times 20 bold', bg='gray', fg='white', height=4, width=8, command=lambda: btnClick(button5)) +button5.grid(row=4, column=1) + +button6 = Button(tk, text=' ', font='Times 20 bold', bg='gray', fg='white', height=4, width=8, command=lambda: btnClick(button6)) +button6.grid(row=4, column=2) + +button7 = Button(tk, text=' ', font='Times 20 bold', bg='gray', fg='white', height=4, width=8, command=lambda: btnClick(button7)) +button7.grid(row=5, column=0) + +button8 = Button(tk, text=' ', font='Times 20 bold', bg='gray', fg='white', height=4, width=8, command=lambda: btnClick(button8)) +button8.grid(row=5, column=1) + +button9 = Button(tk, text=' ', font='Times 20 bold', bg='gray', fg='white', height=4, width=8, command=lambda: btnClick(button9)) +button9.grid(row=5, column=2) + +tk.mainloop() From 15898cefd75fdad0ebbc20269eee414205a2b7ff Mon Sep 17 00:00:00 2001 From: Sumit Suman Date: Fri, 22 Oct 2021 11:31:43 +0530 Subject: [PATCH 2/2] Deleted Mini_Games folder, and uploading a new folder in place of it --- Mini_Games/Tic_Tac_Toe.py | 120 -------------------------------------- 1 file changed, 120 deletions(-) delete mode 100644 Mini_Games/Tic_Tac_Toe.py diff --git a/Mini_Games/Tic_Tac_Toe.py b/Mini_Games/Tic_Tac_Toe.py deleted file mode 100644 index 172c01a..0000000 --- a/Mini_Games/Tic_Tac_Toe.py +++ /dev/null @@ -1,120 +0,0 @@ -#########❤❤❤❤❤❤❤❤❤❤❤❤❤##################### -#########Made with ❤ by Sumit Suman##################### -######### Github: @sumit6258 ###################### - -from tkinter import * -import tkinter.messagebox -tk = Tk() -tk.title("Tic Tac Toe") - -pa = StringVar() -playerb = StringVar() -p1 = StringVar() -p2 = StringVar() - -player1_name = Entry(tk, textvariable=p1, bd=5) -player1_name.grid(row=1, column=1, columnspan=8) -player2_name = Entry(tk, textvariable=p2, bd=5) -player2_name.grid(row=2, column=1, columnspan=8) - -bclick = True -flag = 0 - -def disableButton(): - button1.configure(state=DISABLED) - button2.configure(state=DISABLED) - button3.configure(state=DISABLED) - button4.configure(state=DISABLED) - button5.configure(state=DISABLED) - button6.configure(state=DISABLED) - button7.configure(state=DISABLED) - button8.configure(state=DISABLED) - button9.configure(state=DISABLED) - - - -def btnClick(buttons): - global bclick, flag, player2_name, player1_name, playerb, pa - if buttons["text"] == " " and bclick == True: - buttons["text"] = "X" - bclick = False - playerb = p2.get() + " Wins!" - pa = p1.get() + " Wins!" - checkForWin() - flag += 1 - - - elif buttons["text"] == " " and bclick == False: - buttons["text"] = "O" - bclick = True - checkForWin() - flag += 1 - else: - tkinter.messagebox.showinfo("Tic-Tac-Toe", "Button already Clicked!") - -def checkForWin(): - if (button1['text'] == 'X' and button2['text'] == 'X' and button3['text'] == 'X' or - button4['text'] == 'X' and button5['text'] == 'X' and button6['text'] == 'X' or - button7['text'] =='X' and button8['text'] == 'X' and button9['text'] == 'X' or - button1['text'] == 'X' and button5['text'] == 'X' and button9['text'] == 'X' or - button3['text'] == 'X' and button5['text'] == 'X' and button7['text'] == 'X' or - button1['text'] == 'X' and button2['text'] == 'X' and button3['text'] == 'X' or - button1['text'] == 'X' and button4['text'] == 'X' and button7['text'] == 'X' or - button2['text'] == 'X' and button5['text'] == 'X' and button8['text'] == 'X' or - button7['text'] == 'X' and button6['text'] == 'X' and button9['text'] == 'X'): - disableButton() - tkinter.messagebox.showinfo("Tic-Tac-Toe", pa) - - elif(flag == 8): - tkinter.messagebox.showinfo("Tic-Tac-Toe", "It is a Tie") - - elif (button1['text'] == 'O' and button2['text'] == 'O' and button3['text'] == 'O' or - button4['text'] == 'O' and button5['text'] == 'O' and button6['text'] == 'O' or - button7['text'] == 'O' and button8['text'] == 'O' and button9['text'] == 'O' or - button1['text'] == 'O' and button5['text'] == 'O' and button9['text'] == 'O' or - button3['text'] == 'O' and button5['text'] == 'O' and button7['text'] == 'O' or - button1['text'] == 'O' and button2['text'] == 'O' and button3['text'] == 'O' or - button1['text'] == 'O' and button4['text'] == 'O' and button7['text'] == 'O' or - button2['text'] == 'O' and button5['text'] == 'O' and button8['text'] == 'O' or - button7['text'] == 'O' and button6['text'] == 'O' and button9['text'] == 'O'): - disableButton() - tkinter.messagebox.showinfo("Tic-Tac-Toe", playerb) - - -buttons = StringVar() - -label = Label( tk, text="Player 1:", font='Times 20 bold', bg='white', fg='black', height=1, width=8) -label.grid(row=1, column=0) - - -label = Label( tk, text="Player 2:", font='Times 20 bold', bg='white', fg='black', height=1, width=8) -label.grid(row=2, column=0) - -button1 = Button(tk, text=" ", font='Times 20 bold', bg='gray', fg='white', height=4, width=8, command=lambda: btnClick(button1)) -button1.grid(row=3, column=0) - -button2 = Button(tk, text=' ', font='Times 20 bold', bg='gray', fg='white', height=4, width=8, command=lambda: btnClick(button2)) -button2.grid(row=3, column=1) - -button3 = Button(tk, text=' ',font='Times 20 bold', bg='gray', fg='white', height=4, width=8, command=lambda: btnClick(button3)) -button3.grid(row=3, column=2) - -button4 = Button(tk, text=' ', font='Times 20 bold', bg='gray', fg='white', height=4, width=8, command=lambda: btnClick(button4)) -button4.grid(row=4, column=0) - -button5 = Button(tk, text=' ', font='Times 20 bold', bg='gray', fg='white', height=4, width=8, command=lambda: btnClick(button5)) -button5.grid(row=4, column=1) - -button6 = Button(tk, text=' ', font='Times 20 bold', bg='gray', fg='white', height=4, width=8, command=lambda: btnClick(button6)) -button6.grid(row=4, column=2) - -button7 = Button(tk, text=' ', font='Times 20 bold', bg='gray', fg='white', height=4, width=8, command=lambda: btnClick(button7)) -button7.grid(row=5, column=0) - -button8 = Button(tk, text=' ', font='Times 20 bold', bg='gray', fg='white', height=4, width=8, command=lambda: btnClick(button8)) -button8.grid(row=5, column=1) - -button9 = Button(tk, text=' ', font='Times 20 bold', bg='gray', fg='white', height=4, width=8, command=lambda: btnClick(button9)) -button9.grid(row=5, column=2) - -tk.mainloop()