from tkinter import * from random import randint window = Tk() window.geometry("500x400") window.title("Rock Paper Scissors") choices = ["rock", "paper", "scissor"] def updateChoice(x): compChoice = choices[randint(0,2)] if compChoice == "rock": computer.config(text="Rock") if compChoice == "paper": computer.config(text="Paper") if compChoice == "scissor": computer.config(text="Scissor") if x == "rock": user.config(text="Rock") if x == "paper": user.config(text="Paper") if x == "scissor": user.config(text="Scissor") checkWin(x,compChoice) def checkWin(player, comp): if comp == "rock" and player == "rock": win_msg.config(text="It's a Tie!") win_msg.configure(fg="black") elif comp == "rock" and player == "paper": win_msg.config(text="You Win!") win_msg.configure(fg="green") elif comp == "rock" and player == "scissor": win_msg.config(text="You Lose!") win_msg.configure(fg="red") elif comp == "paper" and player == "rock": win_msg.config(text="You Lose!") win_msg.configure(fg="red") elif comp == "paper" and player == "paper": win_msg.config(text="It's a Tie!") win_msg.configure(fg="black") elif comp == "paper" and player == "scissor": win_msg.config(text="You Win!") win_msg.configure(fg="green") elif comp == "scissor" and player == "rock": win_msg.config(text="You Win!") win_msg.configure(fg="green") elif comp == "scissor" and player == "paper": win_msg.config(text="You Lose!") win_msg.configure(fg="red") elif comp == "scissor" and player == "scissor": win_msg.config(text="It's a tie!") win_msg.configure(fg="black") #Labels Label(window, text="Rock Paper Scissor", font=("Arial", 30)).place(x=125, y=25) Label(window, text="Computer's Choice:", font=("Arial", 20)).place(x=35, y=100) computer = Label(window, text=" ", font=("Arial", 25)) computer.place(x=215, y=135) Label(window, text="User's Choice:", font=("Arial", 20)).place(x=35, y=220) user = Label(window, text=" ", font=("Arial", 25)) user.place(x=215, y=255) win_msg = Label(window, text=" ", font=("Arial", 15)) win_msg.place(x=220, y=75) # Buttons rock = Button(window, text="Rock", font=("Arial", 22), padx=30, pady=3,command=lambda:updateChoice("rock")) rock.place(x=40, y=320) paper = Button(window, text="Paper", font=("Arial", 22), padx=30, pady=3,command=lambda: updateChoice("paper")) paper.place(x=180, y=320) scissor = Button(window, text="Scissor", font=("Arial", 22), padx=30, pady=3,command=lambda: updateChoice("scissor")) scissor.place(x=330, y=320) window.mainloop()