Advertisement
Guest User

Untitled

a guest
Feb 20th, 2019
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.92 KB | None | 0 0
  1. 1)
  2. import Tkinter
  3. win = Tkinter.Tk()
  4. win.title('Converter')
  5.  
  6. def convert():
  7. st = fEntry.get()
  8. v = eval(st)
  9. if type(v) != type('Hello'):
  10. vLabel.config(text=str(v*.3048),justify='right')
  11.  
  12. def convert2():
  13. st=fEntry.get()
  14. v=eval(st)
  15. if type(v)!=type('hello'):
  16. vLabel.config(text=str(v*3.2808),justify='right')
  17.  
  18. def swap():
  19. fLabel.config(text='Meters')
  20. mLabel.config(text='Feet ')
  21. cb.config(command=convert2)
  22. sb.config(command=swap2)
  23.  
  24. def swap2():
  25. fLabel.config(text='Feet ')
  26. mLabel.config(text='Meters')
  27. cb.config(command=convert)
  28. sb.config(command=swap)
  29.  
  30. label = Tkinter.Label(win,text="Convert Feet to Meters",font=('Courier New',30,'bold'))
  31. label.pack()
  32.  
  33. Row2 = Tkinter.Frame(win)
  34. fLabel = Tkinter.Label(Row2,text='Feet ',font=('Courier New',30))
  35. fEntry = Tkinter.Entry(Row2,width=12,bd=4,relief='raised',font=('Courier New',30))
  36. fLabel.pack(side='left')
  37. fEntry.pack(side='left')
  38. Row2.pack()
  39.  
  40. Row3 = Tkinter.Frame(win)
  41. mLabel = Tkinter.Label(Row3,text='Meters',font=('Courier New',30))
  42. vLabel = Tkinter.Label(Row3,width=12,bd=4,relief='raised',text=' ',font=('Courier New',30))
  43. mLabel.pack(side='left')
  44. vLabel.pack(side='left')
  45. Row3.pack()
  46.  
  47. Row4 = Tkinter.Frame(win)
  48. qb = Tkinter.Button(Row4,text='Quit',command=win.destroy,font=('Courier New',30))
  49. cb = Tkinter.Button(Row4,text='Convert',command=convert,font=('Courier New',30))
  50. sb = Tkinter.Button(Row4,text='Swap',command=swap,font=('Courier New',30))
  51. qb.pack(side='left')
  52. cb.pack(side='left')
  53. sb.pack(side='left')
  54. Row4.pack()
  55. win.mainloop()
  56.  
  57.  
  58. 2)
  59. from Tkinter import *
  60. import random
  61. win = Tk()
  62. win.title('Dragon Realm')
  63. win.geometry("%dx%d%+d%+d"%(700,500,0,50))
  64. f = ('Courier New',30)
  65. fb = f + ('bold',)
  66.  
  67. def pbc():
  68. global gameState, userSel, GoodCave, Pic, Cap
  69. if gameState == 0:
  70. gameState = 1
  71. stateDisp(1)
  72. elif gameState == 2:
  73. gameState = 3
  74. if userSel == GoodCave:
  75. Pic = gDragon
  76. Cap = "Gives you his treasure!"
  77. stateDisp (1)
  78. else:
  79. Pic = bDragon
  80. Cap = "Gobbles you down in one bite!"
  81. stateDisp(3)
  82. elif gamestate == 3:
  83. gamestate = 0
  84. stateDisp(0)
  85. stateDisp(3)
  86.  
  87.  
  88. def b1():
  89. global gameState, userSel
  90. if gameState == 1:
  91. userSel = 1
  92. gameState = 1
  93. stateDisp(2)
  94. def b2():
  95. global gameState, userSel
  96. if gameState == 1:
  97. userSel = 2
  98. gameState = 2
  99. stateDisp(2)
  100.  
  101. def Spacer():
  102. return Label(win,text=' ',font=f)
  103.  
  104. introStr = """
  105. You are on a planet
  106. full of dragons.
  107. In front of you
  108. are two caves.
  109. In one cave,
  110. the dragon is friendly
  111. and will share his
  112. treasure with you.
  113. The other dragon is greedy
  114. and hungry, and will eat
  115. you on sight. If you
  116. decide to play you will
  117. have to choose one of
  118. the two caves to enter!
  119. """
  120.  
  121. gameState = 0
  122. GoodCave = 0
  123. userSel = 0
  124.  
  125. for i in range(7):
  126. Spacer().grid(row=0,column=i)
  127. Spacer().grid(row=2,column=i)
  128. Spacer().grid(row=5,column=i)
  129. Globe = PhotoImage(file='globe.gif')
  130. Lcave = PhotoImage(file='CaveLeft.gif')
  131. Rcave = PhotoImage(file='CaveRight.gif')
  132. bDragon = PhotoImage(file='bdragon.gif')
  133. gDragon = PhotoImage(file='gdragon.gif')
  134.  
  135.  
  136. qb = Button(win,text='QUIT',font=fb,command=win.destroy,width=12)
  137. qb.grid(row=4,column=3)
  138. pb = Button(win,text='PLAY',font=fb,width=12,command=pbc)
  139. pb.grid(row=3,column=3)
  140. c1b = Button(win,image=Globe,font=fb,command=b1)
  141. c2b = Button(win,image=Globe,font=fb,command=b2)
  142. c1b.grid(row=1,column=1)
  143. c2b.grid(row=1,column=5)
  144. cL = Label(win,text=introStr,justify='left',font=('Courier New',15))
  145. cL.grid(row=1,column=3)
  146. fPic = Label(win,image=Globe)
  147. capL = Label(win,text="Not Changed",font=fb)
  148.  
  149. def stateDisp(s):
  150. global Pic, Cap, GoodCave
  151. if s == 0:
  152. fPic.grid_remove()
  153. capL.grid_remove()
  154. pb.config(text='PLAY')
  155. pb.grid(row=3,column=3)
  156. c1b.config(image=Globe)
  157. c1b.grid(row=1,column=1)
  158. c2b.config(image=Globe)
  159. c2b.grid(row=1,column=5)
  160. cL.config(text=introStr,font=('Courier New',18))
  161. cL.grid(row=1,column=3)
  162. GoodCave = random.randint(1,2)
  163. elif s == 1:
  164. pb.grid_remove()
  165. c1b.config(image=Lcave)
  166. c2b.config(image=Rcave)
  167. cL.config(text='Choose a Cave',font=fb)
  168. elif s == 2:
  169. c1b.grid_remove()
  170. c2b.grid_remove()
  171. cL.config(height=12)
  172. ttxt = """
  173. You approach the cave...
  174. It is dark and spooky...
  175. A large dragon jumps out in front of you!
  176. He opens his jaws and ...
  177. """
  178. cL.config(text=ttxt)
  179. pb.config(text='CONTINUE')
  180. pb.grid(row=3,column=3)
  181. elif s == 3:
  182. gameState = 0
  183. stateDisp(0)
  184. cL.grid_remove()
  185. fPic.config(image=Pic)
  186. fPic.grid(row=1,column=3)
  187. capL.config(text=Cap)
  188. capL.grid(row=0,column=3)
  189. pb.config(text='PLAY AGAIN')
  190. pb.config()
  191. stateDisp(0)
  192. win.mainloop()
  193.  
  194.  
  195.  
  196.  
  197. 3)
  198. from Tkinter import*
  199. import random
  200.  
  201. class die():
  202. def __init__(self,parent,initVal):
  203. self.value= initVal
  204. self.display= Label(parent,text=str(self.value),font=('Courier New',30),relief='ridge',borderwidth=2)
  205. def roll(self):
  206. self.value= random.randint(1,6)
  207. self.display.config(text=str(self.value))
  208.  
  209. hands = []
  210. win = Tk()
  211. win.title("Dice")
  212. win.geometry("%dx%d%+d%+d"%(700,300,0,50))
  213. dice = Frame(win)
  214. a=die(dice,1)
  215. b=die(dice,1)
  216. c=die(dice,1)
  217. d=die(dice,1)
  218. e=die(dice,1)
  219. a.display.pack(side='left')
  220. b.display.pack(side='left')
  221. c.display.pack(side='left')
  222. d.display.pack(side='left')
  223. e.display.pack(side='left')
  224. dice.pack()
  225.  
  226. label= Label(win,text='5-of-a-kind ',font=('Courier New',30,'bold'))
  227. label.pack()
  228.  
  229. l=[a,b,c,d,e]
  230.  
  231. def Roll():
  232. hands = []
  233. for x in l:
  234. x.roll()
  235. for i in range (6):
  236. j = 0
  237. for y in l:
  238. if (y.value == (i + 1)):
  239. j = j + 1
  240. if (j > 1):
  241. hands.append(j)
  242. string = ''
  243. for x in hands:
  244. if (x == 2):
  245. string = string + "You have a pair.\n"
  246. else:
  247. string = string + "You have " + str(x) + " of a kind.\n"
  248. if (string == ''):
  249. label.config(text="You have nothing useful.\n")
  250. else:
  251. label.config(text=string)
  252.  
  253. button_row = Frame(win)
  254. button = Button(button_row,text='Roll',command=Roll,font=('Courier New',30))
  255. button.pack(side='left')
  256. button_row.pack()
  257.  
  258. win.mainloop()
  259.  
  260.  
  261. 4) I work with a few individuals to get this assignment done. Dylan Choquette helped me out a little and so didn’t Kelsie York. Ben Weeks is also in my hall so we finalized our work together. I have also been working with Lyle, Sam, and Teddy. Most importantly I used the slides and documents you posted on Blackboard.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement