Skip to content

Commit 2338c43

Browse files
authored
Merge pull request larymak#114 from chandrabosep/main
Tic Tac Toe Game
2 parents 63bd471 + d356955 commit 2338c43

File tree

6 files changed

+306
-0
lines changed

6 files changed

+306
-0
lines changed

Alarm clock/README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<h1>Alarm Clock </h1>
2+
3+
<h3> Import Required Library<h3>
4+
<ul>
5+
<h4>from tkinter import *<h4>
6+
<h4>import datetime<h4>
7+
<h4>import time<h4>
8+
<h4>import winsound<h4>
9+
<h4>from threading import *<h4></ul>
10+
<br>
11+
<p> Select your time and and click set alarm </p>
12+
13+
![image](https://user-images.githubusercontent.com/70272542/142355637-6bda8e40-02bf-4bb6-955c-d7d7def5fc55.png)
14+
15+
<p>And that's it. Congratulations You have built your First Alarm clock in python👏👏</p>

Alarm clock/alarm_clock.py

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
# Import Required Library
2+
from tkinter import *
3+
import datetime
4+
import time
5+
import winsound
6+
from threading import *
7+
8+
# Create Object
9+
root = Tk()
10+
11+
# Set geometry
12+
root.geometry("400x200")
13+
14+
# Use Threading
15+
def Threading():
16+
t1=Thread(target=alarm)
17+
t1.start()
18+
19+
def alarm():
20+
# Infinite Loop
21+
while True:
22+
# Set Alarm
23+
set_alarm_time = f"{hour.get()}:{minute.get()}:{second.get()}"
24+
25+
# Wait for one seconds
26+
time.sleep(1)
27+
28+
# Get current time
29+
current_time = datetime.datetime.now().strftime("%H:%M:%S")
30+
print(current_time,set_alarm_time)
31+
32+
# Check whether set alarm is equal to current time or not
33+
if current_time == set_alarm_time:
34+
print("Time to Wake up")
35+
# Playing sound
36+
winsound.PlaySound("sound.wav",winsound.SND_ASYNC)
37+
38+
# Add Labels, Frame, Button, Optionmenus
39+
Label(root,text="Alarm Clock",font=("Helvetica 20 bold"),fg="red").pack(pady=10)
40+
Label(root,text="Set Time",font=("Helvetica 15 bold")).pack()
41+
42+
frame = Frame(root)
43+
frame.pack()
44+
45+
hour = StringVar(root)
46+
hours = ('00', '01', '02', '03', '04', '05', '06', '07',
47+
'08', '09', '10', '11', '12', '13', '14', '15',
48+
'16', '17', '18', '19', '20', '21', '22', '23', '24'
49+
)
50+
hour.set(hours[0])
51+
52+
hrs = OptionMenu(frame, hour, *hours)
53+
hrs.pack(side=LEFT)
54+
55+
minute = StringVar(root)
56+
minutes = ('00', '01', '02', '03', '04', '05', '06', '07',
57+
'08', '09', '10', '11', '12', '13', '14', '15',
58+
'16', '17', '18', '19', '20', '21', '22', '23',
59+
'24', '25', '26', '27', '28', '29', '30', '31',
60+
'32', '33', '34', '35', '36', '37', '38', '39',
61+
'40', '41', '42', '43', '44', '45', '46', '47',
62+
'48', '49', '50', '51', '52', '53', '54', '55',
63+
'56', '57', '58', '59', '60')
64+
minute.set(minutes[0])
65+
66+
mins = OptionMenu(frame, minute, *minutes)
67+
mins.pack(side=LEFT)
68+
69+
second = StringVar(root)
70+
seconds = ('00', '01', '02', '03', '04', '05', '06', '07',
71+
'08', '09', '10', '11', '12', '13', '14', '15',
72+
'16', '17', '18', '19', '20', '21', '22', '23',
73+
'24', '25', '26', '27', '28', '29', '30', '31',
74+
'32', '33', '34', '35', '36', '37', '38', '39',
75+
'40', '41', '42', '43', '44', '45', '46', '47',
76+
'48', '49', '50', '51', '52', '53', '54', '55',
77+
'56', '57', '58', '59', '60')
78+
second.set(seconds[0])
79+
80+
secs = OptionMenu(frame, second, *seconds)
81+
secs.pack(side=LEFT)
82+
83+
Button(root,text="Set Alarm",font=("Helvetica 15"),command=Threading).pack(pady=20)
84+
85+
# Execute Tkinter
86+
root.mainloop()
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<h1>Rock Paper Scissors Game GUI<h1>
2+
3+
<h3>Import Required Library<h3>
4+
<ul>
5+
<h5>from tkinter import *</h5>
6+
<h5>from tkinter import ttk</h5>
7+
<h5>from random import *</h5></ul>
8+
<p>Select Rock Paper or Scissors and click on spin the top label shows whos turn it is and botton label shows who won either computer or you. </p>
9+
10+
![image](https://user-images.githubusercontent.com/70272542/142356847-f734c448-b4b3-407a-9783-fd8af4ecb4e2.png)
11+
<br>
12+
<p>And that's it. Congratulations You have built your First Rock-Paper-Scissors GUI Game
13+
in python👏👏</p>
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
from tkinter import *
2+
from tkinter import ttk
3+
from random import *
4+
5+
root = Tk()
6+
7+
root.geometry("500x500")
8+
9+
root.title("Rock-Paper-Scissors-Game")
10+
11+
list = ["rock","paper","scissors"]
12+
13+
choose_number = randint(0,2)
14+
print(choose_number)
15+
16+
label = Label(root,text="Computer ",width = 20,height=4,font=("algerian",15))
17+
label.pack()
18+
19+
def spin():
20+
choose_number = randint(0,2)
21+
label.config(text=list[choose_number])
22+
if user_select.get() == "Rock":
23+
user_select_value = 0
24+
print(user_select_value)
25+
elif user_select.get() == "Paper":
26+
user_select_value = 1
27+
print(user_select_value)
28+
elif user_select.get() == "Scissors":
29+
user_select_value = 2
30+
print(user_select_value)
31+
32+
if user_select_value == 0:
33+
if choose_number == 0:
34+
wl_label.config(text="Tie! - "+" Computer:Bad luck")
35+
elif choose_number == 1:
36+
wl_label.config(text="YOU Loose - "+" Computer: I am better ")
37+
elif choose_number == 2 :
38+
wl_label.config(text="YOU Won - "+" Computer: You won by luck")
39+
40+
elif user_select_value == 1:
41+
if choose_number == 1:
42+
wl_label.config(text="Tie! - "+" Computer: Nice game")
43+
elif choose_number == 0:
44+
wl_label.config(text="YOU Won - "+" Computer: Shit how you are better")
45+
elif choose_number == 2 :
46+
wl_label.config(text="YOU Loose - "+" Computer: booo")
47+
48+
elif user_select_value == 2:
49+
if choose_number == 2:
50+
wl_label.config(text="Tie!")
51+
elif choose_number == 0:
52+
wl_label.config(text="YOU Loose - "+" Computer: I am playing this game since i was born")
53+
elif choose_number == 1 :
54+
wl_label.config(text="YOU Won")
55+
56+
57+
58+
59+
user_select = ttk.Combobox(root,value=["Rock","Paper","Scissors"])
60+
user_select.current(0)
61+
user_select.pack()
62+
63+
wl_label = Label(root,text="",font=("arial",10),width=50,height=4)
64+
wl_label.pack()
65+
66+
button = Button(root,text="Spin!",font=("bell mt",10),command=spin)
67+
button.pack()
68+
69+
root.mainloop()

Tic Tac Toe Game/README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<h1>Tic Tak Toe Game</h1>
2+
3+
<br><p>You Need to open your favourite Editor ,Run the file game.py<p>
4+
![image](https://user-images.githubusercontent.com/70272542/142355237-3b423833-6f15-4e9b-a82c-1d20b8803a94.png)
5+
<p>And that's it. Congratulations You have built your First Tic Tak Toe Game 👏👏<p>

Tic Tac Toe Game/game.py

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
import random
2+
from tkinter import *
3+
4+
5+
def next_turn(row, column):
6+
global player
7+
8+
if buttons[row][column]['text'] == "" and check_winner() is False:
9+
10+
if player == players[0]: # if its not player 1 turn then it will be else
11+
12+
buttons[row][column]['text'] = player
13+
14+
if check_winner() is False:
15+
player = players[1]
16+
label.config(text=(players[1] + " turn"))
17+
18+
elif check_winner() is True:
19+
label.config(text=(players[0] + " wins"))
20+
21+
elif check_winner() == "Tie":
22+
label.config(text=("Tie!"))
23+
else:
24+
25+
buttons[row][column]['text'] = player
26+
if check_winner() is False:
27+
player = players[0]
28+
label.config(text=(players[0] + " turn"))
29+
30+
elif check_winner() is True:
31+
label.config(text=(players[1] + " wins"))
32+
33+
elif check_winner() == "Tie":
34+
label.config(text="Tie!")
35+
36+
37+
def check_winner():
38+
for row in range(3):
39+
if buttons[row][0]['text'] == buttons[row][1]['text'] == buttons[row][2]['text'] != "":
40+
buttons[row][0].config(bg="light green")
41+
buttons[row][1].config(bg="light green")
42+
buttons[row][2].config(bg="light green")
43+
return True
44+
45+
for column in range(3):
46+
if buttons[0][column]['text'] == buttons[1][column]['text'] == buttons[2][column]['text'] != "":
47+
buttons[0][column].config(bg="light green")
48+
buttons[1][column].config(bg="light green")
49+
buttons[2][column].config(bg="light green")
50+
return True
51+
52+
if buttons[0][0]['text'] == buttons[1][1]['text'] == buttons[2][2]['text'] != "":
53+
buttons[0][0].config(bg="light green")
54+
buttons[1][1].config(bg="light green")
55+
buttons[2][2].config(bg="light green")
56+
return True
57+
58+
elif buttons[0][2]['text'] == buttons[1][1]['text'] == buttons[2][0]['text'] != "":
59+
buttons[0][2].config(bg="light green")
60+
buttons[1][1].config(bg="light green")
61+
buttons[2][0].config(bg="light green")
62+
return True
63+
64+
elif empty_spaces() is False:
65+
for row in range(3):
66+
for column in range(3):
67+
buttons[row][column].config(bg="yellow")
68+
return "Tie"
69+
70+
else:
71+
return False
72+
73+
74+
def empty_spaces():
75+
spaces = 9
76+
for row in range(3):
77+
for column in range(3):
78+
if buttons[row][column]['text'] != "":
79+
spaces -= 1
80+
if spaces == 0:
81+
return False
82+
else:
83+
return True
84+
85+
86+
def new_game():
87+
global player
88+
89+
player = random.choice(players)
90+
label.config(text=player + " turn")
91+
for row in range(3):
92+
for column in range(3):
93+
buttons[row][column].config(text="", bg="#F0F0F0")
94+
95+
96+
windows = Tk()
97+
players = ["x", "o"]
98+
player = random.choice(players)
99+
buttons = [[0, 0, 0],
100+
[0, 0, 0],
101+
[0, 0, 0]]
102+
103+
label = Label(text=player + " turn", font=('bell mt', 40))
104+
label.pack(side="top")
105+
106+
reset_button = Button(text="Restart", font=('bell mt', 20), command=new_game)
107+
reset_button.pack(side="top")
108+
109+
frame = Frame(windows)
110+
frame.pack()
111+
112+
for row in range(3):
113+
for column in range(3):
114+
buttons[row][column] = Button(frame, text="", width=5, height=2, font=('ink free', 25),
115+
command=lambda row=row, column=column: next_turn(row, column))
116+
buttons[row][column].grid(row=row, column=column)
117+
118+
windows.mainloop()

0 commit comments

Comments
 (0)