#Rock
ฝัง
- เผยแพร่เมื่อ 9 ก.พ. 2025
- #rock , #paper & #scissors #game
"Rock, Paper, Scissors" is a classic hand game often used for decision-making or fun.
#rules :
#Players: Two players face each other.
#Choices: Each player simultaneously chooses one of three options:
Rock (represented by a fist)
Paper (represented by an open hand)
Scissors (represented by two fingers extended)
#winning #combinations :
Rock beats Scissors: Rock crushes Scissors.
Scissors beat Paper: Scissors cut Paper.
Paper beats Rock: Paper wraps Rock.
Same choice: It's a tie.
Best of Three: Play three rounds, and whoever wins two wins.
Code:
from tkinter import *
import random
root = Tk()
root.geometry('400x400')
root.resizable(0,0)
root.title('Rock,Paper,Scissors')
root.config(bg ='Pink')
Label(root, text = 'Rock, Paper ,Scissors' , font='arial 16 bold',bg='white',fg="red",pady=15).pack()
user_take = StringVar()
Label(root, text = 'Choose any one: rock, paper ,scissors' , font='arial 15 bold', bg = 'white',fg='red').place(x = 20,y=70)
Entry(root, font = 'arial 15', textvariable = user_take).place(x=90 , y = 130)
comp_pick = random.randint(1,3)
if comp_pick == 1:
comp_pick = 'rock'
elif comp_pick ==2:
comp_pick = 'paper'
else:
comp_pick = 'scissors'
Result = StringVar()
def play():
user_pick = user_take.get()
if user_pick == comp_pick:
Result.set('tie,you both select same')
elif user_pick == 'rock' and comp_pick == 'paper':
Result.set('you loose,computer select paper')
elif user_pick == 'rock' and comp_pick == 'scissors':
Result.set('you win,computer select scissors')
elif user_pick == 'paper' and comp_pick == 'scissors':
Result.set('you loose,computer select scissors')
elif user_pick == 'paper' and comp_pick == 'rock':
Result.set('you win,computer select rock')
elif user_pick == 'scissors' and comp_pick == 'rock':
Result.set('you loose,computer select rock')
elif user_pick == 'scissors' and comp_pick == 'paper':
Result.set('you win ,computer select paper')
else:
Result.set('invalid: choose any one -- rock, paper, scissors')
def Reset():
Result.set("")
user_take.set("")
def Exit():
root.destroy()
Entry(root, font = 'arial 10 bold', textvariable = Result,width = 50,).place(x=25, y = 250)
Button(root, font = 'arial 13 bold', text = 'PLAY' ,padx =5,bg ='white',fg='red' ,command = play).place(x=150,y=190)
Button(root, font = 'arial 13 bold', text = 'RESET' ,padx =5,bg ='white',fg='red' ,command = Reset).place(x=70,y=310)
root.mainloop()
#pythonprogramming #tkinter #module #fungame #beginners #project #rock #paper #scissors #randommodule #winning #combinations