Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from tkinter import *
- from sys import *
- from PIL import Image, ImageTk
- import pygame as py
- import os
- from random import randrange
- py.init()
- thetuple = ('Rock', 'Paper', 'Scissors', 'Lizard', 'Spock')
- #Function runs the actual game.
- def runGame(startWindow):
- #Close [startWindow] before advancing:
- startWindow.destroy()
- startWindow.quit()
- master = Tk()
- master.title('Lets Play!')
- #Function carries on the remainder of the game.
- def carryGame(button_id):
- result = StringVar()
- printResult = Label(master, textvariable = result, font='Optima 30 bold', bg='SpringGreen4')
- printResult.place(x=150, y=300)
- #Computer's move:
- random_Num = randrange(r'../choices/choices.txt')
- if random_Num == 1:
- computer_Move = 'Rock'
- elif random_Num == 2:
- computer_Move = 'Paper'
- elif random_Num == 3:
- computer_Move = 'Scissors'
- elif random_Num == 4:
- computer_Move == 'Lizard'
- else:
- computer_Move == 'Spock'
- if button_id == 1:
- player_Move = 'Rock'
- elif button_id == 2:
- player_Move = 'Paper'
- elif button_id == 3:
- player_Move = 'Scissors'
- elif button_id == 4:
- player_Move = 'Lizard'
- else:
- player_Move = 'Spock'
- #Rock button
- rock_Button = Button(master, width=15, height=7, command=lambda:carryGame(1))
- rock_photo=PhotoImage(file=r'../images/rock.jpeg')
- rock_Button.config(image=rock_photo,width="120",height="120")
- rock_Button.place(x=17, y=70)
- #Paper button
- paper_Button = Button(master, width=15, height=7, command=lambda:carryGame(2))
- paper_photo=PhotoImage(file=r'../images/paper.jpeg')
- paper_Button.config(image=paper_photo,width="120",height="120")
- paper_Button.place(x=167, y=70)
- #Scissors button
- scissors_Button = Button(master, width=15, height=7, command=lambda:carryGame(3))
- scissors_photo=PhotoImage(file=r'../images/scissors.jpeg')
- scissors_Button.config(image=scissors_photo,width="120",height="120")
- scissors_Button.place(x=317, y=70)
- lizard_Button = Button(master, width=15, height=7, command=lambda:carryGame(4))
- lizard_photo=PhotoImage(file=r'../images/lizard.jpeg')
- lizard_Button.config(image=lizard_photo,width='120', height='120')
- lizard_Button.place(x=467, y=70)
- spock_Button = Button(master, width=15, height=7, command=lambda:carryGame(5))
- spock_photo=PhotoImage(r'../images/spock.jpeg')
- spock_Button.config(image=spock_photo,width='120',height='120')
- spock_Button.place(x=617, y=70)
- label_1 = Label(master, text='It is quite simple, choose. Bazinga-', font='Comic Sans 18 bold', bg='SpringGreen4')
- label_1.pack(side=TOP)
- label_2 = Label(master, text='Your worthy opponent picked:', font='Optima 20 bold', bg='SpringGreen4')
- label_2.place(x=70, y=240)
- #Locks window size
- master.maxsize(700, 400)
- master.minsize(700, 400)
- #Sets window background to SpringGreen4
- master.config(background='SpringGreen4')
- master.mainloop()
- def startScreen():
- #Plays music for the application
- def playMusic(fileName):
- py.mixer.music.load(fileName)
- py.mixer.music.play()
- #Start Window
- startWindow = Tk()
- startWindow.title(thetuple)
- #Imports image as title
- load = Image.open('../images/title.png')
- render = ImageTk.PhotoImage(load)
- img = Label(startWindow, image=render, bd=0)
- img.image = render
- img.place(x=-100, y=-65)
- clickToPlay = Button(startWindow, text='Play!', width=8, font='Optima 20 bold', bg='Black', fg='Yellow', relief=RIDGE, bd=0, command=lambda:runGame(startWindow))
- clickToPlay.place(x=75, y=125)
- #Start Screen Music
- playMusic(r'../audio/sheldon.mp3')
- #Locks window size
- startWindow.maxsize(300, 250)
- startWindow.minsize(300, 250)
- #Sets window background to a grey(ish) color
- startWindow.config(background='LightCyan4')
- startWindow.mainloop()
- startScreen()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement