Rock, Paper and Scissors Game Code GUI in Python.














import tkinter
from tkinter import *
from random import *
import time

game = Tk()
#game.resizable(width=False,height=False)game.minsize(width=400,height=400)
mainLable = Label(game,bd="5",cursor="dot",padx="5",pady="5",justify="center", font="30",text="WELCOME TO Rock,Paper and Scissors Game...!",fg="Red")
user=0def one():
    user=1    b1.configure(bg="Yellow")
    cLable.grid(columnspan=3)
    l.grid(columnspan=3)
    l.configure(text="Selecting.." ,fg="orange")
    l.configure(text="Selecting....", fg="Yellow")
    l.configure(text="Selecting......", fg="Green")

    b4.grid(row=6, column=0)
    b5.grid(row=6, column=1)
    b6.grid(row=6, column=2)
    l2.grid(columnspan=3)

    if (computer == user):
        l2.configure(text="DRAW")
    elif user == 1 and computer == 2:
        l2.configure(text="COMPUTER WINS")
    elif user == 1 and computer == 3:
        l2.configure(text="You WIN")
    elif user == 2 and computer == 1:
        l2.configure(text="You WIN")
    elif user == 2 and computer == 3:
        l2.configure(text="COMPUTER WINS")
    elif user == 3 and computer == 1:
        l2.configure(text="COMPUTER WINS")
    elif user == 3 and computer == 2:
        l2.configure(text="You WIN")
    else:
        l2.configure(text="Nothing")


def two():
    user=2    b2.configure(bg="Yellow")
    cLable.grid(columnspan=3)
    l.grid(columnspan=3)
    l.configure(text="Selecting..", fg="orange")
    l.configure(text="Selecting....", fg="Yellow")
    l.configure(text="Selecting......", fg="Green")

    b4.grid(row=6, column=0)
    b5.grid(row=6, column=1)
    b6.grid(row=6, column=2)
    l2.grid(columnspan=3)

    if (computer == user):
        l2.configure(text="DRAW")
    elif user == 1 and computer == 2:
        l2.configure(text="COMPUTER WINS")
    elif user == 1 and computer == 3:
        l2.configure(text="You WIN")
    elif user == 2 and computer == 1:
        l2.configure(text="You WIN")
    elif user == 2 and computer == 3:
        l2.configure(text="COMPUTER WINS")
    elif user == 3 and computer == 1:
        l2.configure(text="COMPUTER WINS")
    elif user == 3 and computer == 2:
        l2.configure(text="You WIN")
    else:
        l2.configure(text="Nothing")


def three():
    user=3    b3.configure(bg="Yellow")
    cLable.grid(columnspan=3)
    l.grid(columnspan=3)
    l.configure(text="Selecting..", fg="orange")
    l.configure(text="Selecting....", fg="Yellow")
    l.configure(text="Selecting......", fg="Green")
    b4.grid(row=6, column=0)
    b5.grid(row=6, column=1)
    b6.grid(row=6, column=2)
    l2.grid(columnspan=3)

    if (computer == user):
        l2.configure(text="DRAW")
    elif user == 1 and computer == 2:
        l2.configure(text="COMPUTER WINS")
    elif user == 1 and computer == 3:
        l2.configure(text="You WIN")
    elif user == 2 and computer == 1:
        l2.configure(text="You WIN")
    elif user == 2 and computer == 3:
        l2.configure(text="COMPUTER WINS")
    elif user == 3 and computer == 1:
        l2.configure(text="COMPUTER WINS")
    elif user == 3 and computer == 2:
        l2.configure(text="You WIN")
    else:
        l2.configure(text="Nothing")


photo1 = PhotoImage(file="rock.png")
photo2 = PhotoImage(file="scissors.png")
photo3 = PhotoImage(file="paper.png")
mainLable.grid(columnspan=3)
pLable1 = Label(game, image=photo1,width=100,height=100)
pLable2 = Label(game, image=photo2,width=100,height=100)
pLabel3 = Label(game, image=photo3,width=100,height=100)
pLable1.grid(row=1,column=0,sticky=W)
pLabel3.grid(row=1,column=1,sticky=W)
pLable2.grid(row=1,column=2, sticky=W)

tLable= Label(game,bd="5",cursor="dot",padx="5",pady="5",justify="center", font="20",fg="Red",text="Choose Rock,Paper or Scissors Option")

b1=Button(game,command=one,highlightcolor="Yellow",text="Rock",fg="red",padx="5",pady="5",bd="5")
b2=Button(game,command=two,text="Paper",fg="Brown",padx="5",pady="5",bd="5")
b3=Button(game,command=three,text="Scissors",fg="Green",padx="5",pady="5",bd="5")

tLable.grid(columnspan=3)


b1.grid(row=3,column=0)
b2.grid(row=3,column=1)
b3.grid(row=3,column=2)

cLable=Label(game,bd="5",cursor="dot",padx="5",pady="5",justify="center", font="20",fg="Red",text="Computer is Chossing Now...")


b4=Button(game,highlightcolor="Yellow",text="Rock",fg="red",padx="5",pady="5",bd="5")
b5=Button(game,text="Paper",fg="Brown",padx="5",pady="5",bd="5")
b6=Button(game,text="Scissors",fg="Green",padx="5",pady="5",bd="5")

l=Label(game,text="Selecting",bd="5",cursor="dot",padx="5",pady="5",justify="center", font="20")

computer=randint(1,3)
if(computer==1):
    b4.configure(bg="Yellow")
elif computer==2:
    b5.configure(bg="Yellow")
else:
    b6.configure(bg="Yellow")


l2=Label(game,text="sdfgsdf",bd="5",cursor="dot",padx="5",pady="5",justify="center", font="20")






game.mainloop()

Comments

Popular Posts