Advertisement
Guest User

Untitled

a guest
Dec 3rd, 2016
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.92 KB | None | 0 0
  1. from tkinter import *
  2. from sys import *
  3. from PIL import Image, ImageTk
  4. import pygame as py
  5. import os
  6. from random import randrange
  7.  
  8. py.init()
  9. thetuple = ('Rock', 'Paper', 'Scissors', 'Lizard', 'Spock')
  10. #Function runs the actual game.
  11. def runGame(startWindow):
  12.  
  13. #Close [startWindow] before advancing:
  14. startWindow.destroy()
  15. startWindow.quit()
  16.  
  17. master = Tk()
  18. master.title('Lets Play!')
  19.  
  20. #Function carries on the remainder of the game.
  21. def carryGame(button_id):
  22.  
  23. result = StringVar()
  24. printResult = Label(master, textvariable = result, font='Optima 30 bold', bg='SpringGreen4')
  25. printResult.place(x=150, y=300)
  26.  
  27. #Computer's move:
  28. random_Num = randrange(r'../choices/choices.txt')
  29.  
  30. if random_Num == 1:
  31. computer_Move = 'Rock'
  32.  
  33. elif random_Num == 2:
  34. computer_Move = 'Paper'
  35.  
  36. elif random_Num == 3:
  37. computer_Move = 'Scissors'
  38.  
  39. elif random_Num == 4:
  40. computer_Move == 'Lizard'
  41.  
  42. else:
  43. computer_Move == 'Spock'
  44.  
  45.  
  46. if button_id == 1:
  47. player_Move = 'Rock'
  48.  
  49. elif button_id == 2:
  50. player_Move = 'Paper'
  51.  
  52. elif button_id == 3:
  53. player_Move = 'Scissors'
  54.  
  55. elif button_id == 4:
  56. player_Move = 'Lizard'
  57.  
  58. else:
  59. player_Move = 'Spock'
  60.  
  61. #Rock button
  62. rock_Button = Button(master, width=15, height=7, command=lambda:carryGame(1))
  63. rock_photo=PhotoImage(file=r'../images/rock.jpeg')
  64. rock_Button.config(image=rock_photo,width="120",height="120")
  65. rock_Button.place(x=17, y=70)
  66.  
  67. #Paper button
  68. paper_Button = Button(master, width=15, height=7, command=lambda:carryGame(2))
  69. paper_photo=PhotoImage(file=r'../images/paper.jpeg')
  70. paper_Button.config(image=paper_photo,width="120",height="120")
  71. paper_Button.place(x=167, y=70)
  72.  
  73. #Scissors button
  74. scissors_Button = Button(master, width=15, height=7, command=lambda:carryGame(3))
  75. scissors_photo=PhotoImage(file=r'../images/scissors.jpeg')
  76. scissors_Button.config(image=scissors_photo,width="120",height="120")
  77. scissors_Button.place(x=317, y=70)
  78.  
  79. lizard_Button = Button(master, width=15, height=7, command=lambda:carryGame(4))
  80. lizard_photo=PhotoImage(file=r'../images/lizard.jpeg')
  81. lizard_Button.config(image=lizard_photo,width='120', height='120')
  82. lizard_Button.place(x=467, y=70)
  83.  
  84. spock_Button = Button(master, width=15, height=7, command=lambda:carryGame(5))
  85. spock_photo=PhotoImage(r'../images/spock.jpeg')
  86. spock_Button.config(image=spock_photo,width='120',height='120')
  87. spock_Button.place(x=617, y=70)
  88.  
  89. label_1 = Label(master, text='It is quite simple, choose. Bazinga-', font='Comic Sans 18 bold', bg='SpringGreen4')
  90. label_1.pack(side=TOP)
  91.  
  92. label_2 = Label(master, text='Your worthy opponent picked:', font='Optima 20 bold', bg='SpringGreen4')
  93. label_2.place(x=70, y=240)
  94.  
  95. #Locks window size
  96. master.maxsize(700, 400)
  97. master.minsize(700, 400)
  98.  
  99. #Sets window background to SpringGreen4
  100. master.config(background='SpringGreen4')
  101.  
  102. master.mainloop()
  103.  
  104. def startScreen():
  105.  
  106. #Plays music for the application
  107. def playMusic(fileName):
  108. py.mixer.music.load(fileName)
  109. py.mixer.music.play()
  110.  
  111. #Start Window
  112. startWindow = Tk()
  113. startWindow.title(thetuple)
  114.  
  115. #Imports image as title
  116. load = Image.open('../images/title.png')
  117. render = ImageTk.PhotoImage(load)
  118. img = Label(startWindow, image=render, bd=0)
  119. img.image = render
  120. img.place(x=-100, y=-65)
  121.  
  122. clickToPlay = Button(startWindow, text='Play!', width=8, font='Optima 20 bold', bg='Black', fg='Yellow', relief=RIDGE, bd=0, command=lambda:runGame(startWindow))
  123. clickToPlay.place(x=75, y=125)
  124.  
  125. #Start Screen Music
  126. playMusic(r'../audio/sheldon.mp3')
  127.  
  128. #Locks window size
  129. startWindow.maxsize(300, 250)
  130. startWindow.minsize(300, 250)
  131.  
  132. #Sets window background to a grey(ish) color
  133. startWindow.config(background='LightCyan4')
  134.  
  135. startWindow.mainloop()
  136.  
  137. startScreen()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement