I coded this game myself. It is a guessing game regarding 2 players.
from random import randint
from tkinter import *
p1 = 0
p2 = 0
while p1 < 3 and p2 < 3:
answer = randint(0,16)
wrong_answer = randint(0,16)
wrong_answer1 = randint(0,16)
s_list = ["apple","book","phone","sheep","ruler","pen","eraser","knife","cement","Google","file","stapler","thermometer","box","glue","yes","no"]
hint_list = ["Fruit","Read","Technology","Animal","Measure Length","Writing","Stationary","Cut food", "Building Material","Search Engine","Paper organizer","Binding papers together","Temperature","Storage","Attach things together","Approval","Disapproval"]
secret_word = s_list[answer]
hint = f'Hint:{hint_list[answer]}'
incorrect = s_list[answer]
incorrect1 = s_list[answer]
master = Tk()
master.title("2 Players Guessing Game!")
master.geometry('700x900+90+90')
def random1():
global p1
p1 += 1
label4["text"] = "Correct! Score:",p1 ,p2
def random2():
global p2
p2 += 1
label4["text"] = "Incorrect! Score:",p1 ,p2
def random3():
global p2
p2 += 1
label4["text"] = "Correct! Score:",p1 ,p2
def random4():
global p1
p1 += 1
label4["text"] = "Incorrect! Score:",p1 ,p2
label = Label(master, text="2 Player Guessing Game!", font = "Arial 14")
label2 = Label(master, text="<- P1", font = "Arial 14")
label3 = Label(master, text="P2 ->", font = "Arial 14")
button = Button(master, text=secret_word, font = "Arial 14", command=random1)
button2 = Button(master, text=incorrect, font = "Arial 14", command=random2)
button3 = Button(master, text=incorrect1, font = "Arial 14", command=random2)
button4 = Button(master, text=secret_word, font = "Arial 14", command=random3)
button5 = Button(master, text=incorrect, font = "Arial 14", command=random4)
button6 = Button(master, text=incorrect1, font = "Arial 14", command=random4)
label4 = Label(master, text=hint, font = "Arial 14")
label.pack()
label2.pack()
label3.pack()
label4.pack()
button.pack(side=LEFT)
button2.pack(side=LEFT)
button3.pack(side=LEFT)
button4.pack(side=RIGHT)
button5.pack(side=RIGHT)
button6.pack(side=RIGHT)
if p1 == 3:
label["text"] = "Player 1 won!"
exit()
elif p2 == 3:
label["text"] = "Player 2 won!"
exit()
else:
continue
Before I added this "continue" , I could print Tk properly but could not loop. After adding "continue", my Tk can't even load now. Why? Please help. Thanks.
mainloop()
The reason why I did not use PyGame is because I wanted my game to be a "Answer first, get point" type of game.