|  | 
|  | 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() | 
0 commit comments