|
| 1 | +from tkinter import * |
| 2 | +from tkinter.ttk import * |
| 3 | +import random |
| 4 | +window1 = Tk() |
| 5 | +window1.title('Rock Paper Scissors') |
| 6 | +window1.geometry('500x500') |
| 7 | +style1 = Style() |
| 8 | +style1.configure('W.TButton', foreground = 'green', font = ('Bernard MT', 30, 'bold')) |
| 9 | +lb1 = Label(window1, text = 'Rock Paper Scissors') |
| 10 | +lb1.pack(pady = 15) |
| 11 | +lb7 = Label(window1, text = 'Choose and then press start game to play:') |
| 12 | +lb7.pack(pady = 15) |
| 13 | +lit1 = ['Rock', 'Paper', 'Scissor'] |
| 14 | +your_score = 0 |
| 15 | +computer_score = 0 |
| 16 | +cho = 3 |
| 17 | +def clicked2(): |
| 18 | + global cho |
| 19 | + lb9.configure(text = 'You have choosen Rock') |
| 20 | + cho = 0 |
| 21 | +def clicked3(): |
| 22 | + global cho |
| 23 | + lb9.configure(text='You have choosen Paper') |
| 24 | + cho = 1 |
| 25 | +def clicked4(): |
| 26 | + global cho |
| 27 | + lb9.configure(text='You have choosen Scissor') |
| 28 | + cho = 2 |
| 29 | +btn2 = Button(window1, text = 'Rock', command = clicked2) |
| 30 | +btn2.pack() |
| 31 | +btn3 = Button(window1, text = 'Paper', command = clicked3) |
| 32 | +btn3.pack() |
| 33 | +btn4 = Button(window1, text = 'Scissor', command = clicked4) |
| 34 | +btn4.pack() |
| 35 | +lb9 = Label(window1, text = '') |
| 36 | +lb9.pack(pady = 10) |
| 37 | +lb13 = Label(window1, text = 'Computer: ') |
| 38 | +lb13.pack() |
| 39 | +lb2 = Label(window1, text = '') |
| 40 | +lb2.pack(pady = 10) |
| 41 | + |
| 42 | +def clicked1(): |
| 43 | + global cho |
| 44 | + if cho == 3: |
| 45 | + lb1.configure(text='Please choose an option to play!', foreground = 'purple') |
| 46 | + return |
| 47 | + res = random.choice(lit1) |
| 48 | + res1 = 4 |
| 49 | + if res == 'Rock': |
| 50 | + res1 = 0 |
| 51 | + elif res == 'Paper': |
| 52 | + res1 = 1 |
| 53 | + elif res == 'Scissor': |
| 54 | + res1 = 2 |
| 55 | + lb2.configure(text = res) |
| 56 | + if res1 == cho: |
| 57 | + global your_score |
| 58 | + lb1.configure(text = 'You Win', foreground = 'green') |
| 59 | + your_score = your_score + 1 |
| 60 | + lb4.configure(text = 'Your Score: '+ str(your_score)) |
| 61 | + elif res1 != cho: |
| 62 | + global computer_score |
| 63 | + lb1.configure(text='You Lose', foreground='red') |
| 64 | + computer_score = computer_score +1 |
| 65 | + lb5.configure(text='Computer Score: ' + str(computer_score)) |
| 66 | + cho = 3 |
| 67 | +btn1 = Button(window1, text = 'START GAME', command = clicked1, style = 'W.TButton') |
| 68 | +btn1.pack(pady = 10) |
| 69 | +def clicked5(): |
| 70 | + global your_score |
| 71 | + global computer_score |
| 72 | + computer_score = 0 |
| 73 | + your_score =0 |
| 74 | + lb4.configure(text='Your Score: ' + str(your_score)) |
| 75 | + lb5.configure(text='Computer Score: ' + str(computer_score)) |
| 76 | + lb2.configure(text = '') |
| 77 | + lb9.configure(text = '') |
| 78 | +btn1 = Button(window1, text = 'Reset Scoreboard', command = clicked5) |
| 79 | +btn1.pack(pady = 10) |
| 80 | +lb1 = Label(window1, text = '') |
| 81 | +lb1.pack() |
| 82 | +lb3 = Label(window1, text = 'Note: Choose a button each time and then press start game to play!') |
| 83 | +lb3.pack(pady = 10) |
| 84 | +lb4 = Label(window1, text = 'Your Score: 0') |
| 85 | +lb4.pack() |
| 86 | +lb5 = Label(window1, text = 'Computer Score: 0') |
| 87 | +lb5.pack() |
| 88 | +window1.mainloop() |
0 commit comments