Advertisement
Guest User

Untitled

a guest
Apr 28th, 2019
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 14.03 KB | None | 0 0
  1. from tkinter import *
  2. import tkinter as GUI
  3. import tkinter as tk
  4. import tkinter.messagebox
  5. import random
  6. from functools import partial
  7. import time
  8. import os
  9. import sys
  10.  
  11. def TheGame():
  12.  
  13. def play2():
  14. button1.config(state='disabled', background="cadetblue",fg="red")
  15. dice1 = random.randint(1,6)
  16. dice2 = random.randint(1,6)
  17. global total
  18.  
  19. total = dice1 + dice2
  20. tkinter.Label(rooter, text="you have rolled " + str(dice1)).grid(row=4)
  21. tkinter.Label(rooter, text="you have rolled " + str(dice2)).grid(row=5)
  22.  
  23. global button5
  24. button5=Button(rooter, text="Roll again",command=play4)
  25. button5.grid(row=8)
  26.  
  27.  
  28. if total % 2 == 0:
  29. tkinter.Label(rooter, text="Even number + 10 Points to total score").grid(row=6)
  30. total = total + 10
  31. tkinter.Label(rooter, text="Your total score is " + str(total)).grid(row=7)
  32. else:
  33. tkinter.Label(rooter, text="Odd number - 5 Points from Total score").grid(row=6)
  34. total = total - 5
  35. tkinter.Label(rooter, text="Your total score is " + str(total)).grid(row=7)
  36.  
  37. if dice1 == dice2:
  38. button1.config(state='normal', background="white",fg="red",text="DOUBLE ROLL AGAIN",command=double1)
  39.  
  40.  
  41.  
  42. def play3():
  43. button2.configure(state=DISABLED, background="cadetblue",fg="red")
  44. dice4 = random.randint(1,6)
  45. dice5 = random.randint(1,6)
  46. global total2
  47.  
  48. total2 = dice4 + dice5
  49. tkinter.Label(rooter, text="you have rolled: " + str(dice4)).grid(row=4, column=4)
  50. tkinter.Label(rooter, text="you have rolled: " + str(dice5)).grid(row=5, column=4)
  51.  
  52. global button6
  53. button6=Button(rooter, text="Roll again",command=play5)
  54. button6.grid(row=8,column=4)
  55.  
  56. if total2 % 2 == 0:
  57. tkinter.Label(rooter, text="Even number + 10 Points to total score").grid(row=6,column=4)
  58. total2 = total2 + 10
  59. tkinter.Label(rooter, text="Your total score is " + str(total2)).grid(row=7,column=4)
  60. else:
  61. tkinter.Label(rooter, text="Odd number - 5 Points from Total score").grid(row=6,column=4)
  62. total2 = total2 - 5
  63. tkinter.Label(rooter, text="Your total score is " + str(total2)).grid(row=7,column=4)
  64.  
  65. if dice4 == dice5:
  66. button2.config(state='normal', background="white",fg="red",text="DOUBLE ROLL AGAIN",command=doubledice2)
  67.  
  68.  
  69. def play5():
  70. dice1 = random.randint(1,6)
  71. dice2 = random.randint(1,6)
  72. global total2
  73.  
  74. global button8
  75. button8 = Button(rooter, text="Roll again",command=play8)
  76. button8.grid(row=20,column=4)
  77.  
  78. total2 = total2 + dice1 + dice2
  79. tkinter.Label(rooter, text="you have rolled " + str(dice1)).grid(row=12,column=4)
  80. tkinter.Label(rooter, text="you have rolled " + str(dice2)).grid(row=13,column=4)
  81.  
  82. if total2 % 2 == 0:
  83. tkinter.Label(rooter, text="Even number + 10 Points to total score").grid(row=14,column=4)
  84. total2 = total2 + 10
  85. tkinter.Label(rooter, text="Your total score is " + str(total2)).grid(row=15,column=4)
  86. button6.config(state='disabled')
  87. else:
  88. tkinter.Label(rooter, text="Odd number - 5 Points from Total score").grid(row=14,column=4)
  89. total2 = total2 - 5
  90. tkinter.Label(rooter, text="Your total score is " + str(total2)).grid(row=15,column=4)
  91. button6.config(state='disabled',background="white",fg="grey",text='Done')
  92.  
  93. if dice1 == dice2:
  94. button6.config(state='normal', background="white",fg="red",text="DOUBLE ROLL AGAIN")
  95.  
  96. def play4():
  97. dice1 = random.randint(1,6)
  98. dice2 = random.randint(1,6)
  99. global total
  100.  
  101. global button7
  102. button7 = Button(rooter, text="Roll again",command=play7)
  103. button7.grid(row=20)
  104.  
  105. total = total + dice1 + dice2
  106. tkinter.Label(rooter, text="you have rolled " + str(dice1)).grid(row=12)
  107. tkinter.Label(rooter, text="you have rolled " + str(dice2)).grid(row=13)
  108.  
  109. if total % 2 == 0:
  110. tkinter.Label(rooter, text="Even number + 10 Points to total score").grid(row=14)
  111. total = total + 10
  112. tkinter.Label(rooter, text="Your total score is " + str(total)).grid(row=15)
  113. button5.config(state='disabled',background='white',fg="grey",text='Done')
  114. else:
  115. tkinter.Label(rooter, text="Odd number - 5 Points from Total score").grid(row=14)
  116. total = total - 5
  117. tkinter.Label(rooter, text="Your total score is " + str(total)).grid(row=15)
  118. button5.config(state='disabled',background='white',fg="grey",text='Done')
  119.  
  120. if dice1 == dice2:
  121. button5.config(state='normal', background="white",fg="red",text="DOUBLE ROLL AGAIN")
  122.  
  123. def play7():
  124. dice1 = random.randint(1,6)
  125. dice2 = random.randint(1,6)
  126. global total
  127.  
  128. total = total + dice1 + dice2
  129. tkinter.Label(rooter, text="you have rolled " + str(dice1)).grid(row=21)
  130. tkinter.Label(rooter, text="you have rolled " + str(dice2)).grid(row=22)
  131.  
  132.  
  133. if total % 2 == 0:
  134. tkinter.Label(rooter, text="Even number + 10 Points to total score").grid(row=23)
  135. total=total+10
  136. tkinter.Label(rooter, text="Your total score is " + str(total)).grid(row=24)
  137. button7.config(state='disabled',background='white',fg='grey',text='Done')
  138. else:
  139. tkinter.Label(rooter, text="Odd number - 5 Points from Total score").grid(row=23)
  140. total = total - 5
  141. tkinter.Label(rooter, text="Your total score is " + str(total)).grid(row=24)
  142. button7.config(state='disabled',background='white',fg="grey",text='Done')
  143.  
  144. if dice1 == dice2:
  145. button7.config(state='normal',background='whote',fg='red',text='DOUBLE ROLL AGAIN')
  146.  
  147. def play8():
  148. dice1 = random.randint(1,6)
  149. dice2 = random.randint(1,6)
  150. global total2
  151.  
  152. total2 = total2 + dice1 + dice2
  153. tkinter.Label(rooter, text="you have rolled " + str(dice1)).grid(row=21,column=4)
  154. tkinter.Label(rooter, text="you have rolled " + str(dice2)).grid(row=22,column=4)
  155.  
  156.  
  157. if total2 % 2 == 0:
  158. tkinter.Label(rooter, text="Even number + 10 Points to total score").grid(row=23,column=4)
  159. total2 = total2 +10
  160. tkinter.Label(rooter, text="Your total score is " + str(total2)).grid(row=24,column=4)
  161. button8.config(state='disabled',background='white',fg='grey',text='Done')
  162. else:
  163. tkinter.Label(rooter, text="Odd number - 5 Points from Total score").grid(row=23,column=4)
  164. total2 = total2 - 5
  165. tkinter.Label(rooter, text="Your total score is " + str(total2)).grid(row=24,column=4)
  166. button8.config(state='disabled',background='white',fg="grey",text='Done')
  167.  
  168. if dice1 == dice2:
  169. button8.config(state='normal',background='white',fg='red',text='DOUBLE ROLL AGAIN')
  170.  
  171.  
  172.  
  173. def double1():
  174. doubledice1 = random.randint(1,6)
  175. doubledice2 = random.randint(1,6)
  176. global total
  177.  
  178. total = total + doubledice1 + doubledice2
  179. tkinter.Label(rooter, text="you have rolled " + str(doubledice1)).grid(row=4)
  180. tkinter.Label(rooter, text="you have rolled " + str(doubledice2)).grid(row=5)
  181.  
  182. if total % 2 == 0:
  183. tkinter.Label(rooter, text="Even number + 10 Points to total score").grid(row=6)
  184. total = total + 10
  185. tkinter.Label(rooter, text="Your total score is " + str(total)).grid(row=7)
  186. button1.config(state='disabled', background="cadetblue",fg="red")
  187. else:
  188. tkinter.Label(rooter, text="Odd number - 5 Points from Total score").grid(row=6)
  189. total = total - 5
  190. tkinter.Label(rooter, text="Your total score is " + str(total)).grid(row=7)
  191. button1.config(state='disabled', background="cadetblue",fg="red")
  192.  
  193. #tomorrow = finish remaking all the doubles like the one above... help me please....#
  194.  
  195. def double2():
  196. doubledice3 = random.randint(1,6)
  197. doubledice4 = random.randint(1,6)
  198.  
  199. def double3():
  200. doubledice5 = random.randint(1,6)
  201. doubledice6 = random.randint(1,6)
  202.  
  203. def double4():
  204. doubledice7 = random.randint(1,6)
  205. doubledice8 = random.randint(1,6)
  206.  
  207. def double5():
  208. doubledice9 = random.randint(1,6)
  209. doubledice10 = random.randint(1,6)
  210.  
  211. def double6():
  212. doubledice11 = random.randint(1,6)
  213. doubledice12 = random.randint(1,6)
  214.  
  215.  
  216. rooter = Toplevel()
  217. rooter.geometry("800x500")
  218.  
  219. label = Label(rooter)
  220. label.img = PhotoImage(file="xd.gif")
  221. label.config(image=label.img)
  222. label.grid(row=1)
  223.  
  224.  
  225. button1 = Button(rooter, text="Player One's Roll Buttton",command=play2)
  226. button2 = Button(rooter, text="Player Two's Roll Button",command=partial(play3))
  227. button2.grid(row=2,column=4)
  228. tkinter.Label(rooter, text="Player One's Turn")
  229. button1.grid(row=2,column=0)
  230. rooter.mainloop()
  231.  
  232. def thelogin():
  233. creds = 'tempfile.temp' # This just sets the variable creds to 'tempfile.temp'
  234.  
  235. def Signup(): # This is the signup definition,
  236. global pwordE # These globals just make the variables global to the entire script, meaning any definition can use them
  237. global nameE
  238. global roots
  239.  
  240. roots = Tk() # This creates the window, just a blank one.
  241. roots.title('Signup') # This renames the title of said window to 'signup'
  242. intruction = Label(roots, text='Please Enter new Credidentials\n') # This puts a label, so just a piece of text saying 'please enter blah'
  243. intruction.grid(row=0, column=0, sticky=E) # This just puts it in the window, on row 0, col 0. If you want to learn more look up a tkinter tutorial :)
  244.  
  245. nameL = Label(roots, text='New Username: ') # This just does the same as above, instead with the text new username.
  246. pwordL = Label(roots, text='New Password: ') # ^^
  247. nameL.grid(row=1, column=0, sticky=W) # Same thing as the instruction var just on different rows. :) Tkinter is like that.
  248. pwordL.grid(row=2, column=0, sticky=W) # ^^
  249.  
  250. nameE = Entry(roots) # This now puts a text box waiting for input.
  251. pwordE = Entry(roots, show='*') # Same as above, yet 'show="*"' What this does is replace the text with *, like a password box :D
  252. nameE.grid(row=1, column=1) # You know what this does now :D
  253. pwordE.grid(row=2, column=1) # ^^
  254.  
  255. signupButton = Button(roots, text='Signup', command=FSSignup) # This creates the button with the text 'signup', when you click it, the command 'fssignup' will run. which is the def
  256. signupButton.grid(columnspan=2, sticky=W)
  257. roots.mainloop() # This just makes the window keep open, we will destroy it soon
  258.  
  259. def FSSignup():
  260. with open(creds, 'w') as f: # Creates a document using the variable we made at the top.
  261. f.write(nameE.get()) # nameE is the variable we were storing the input to. Tkinter makes us use .get() to get the actual string.
  262. f.write('\n') # Splits the line so both variables are on different lines.
  263. f.write(pwordE.get()) # Same as nameE just with pword var
  264. f.close() # Closes the file
  265.  
  266. roots.destroy() # This will destroy the signup window. :)
  267. Login() # This will move us onto the login definition :D
  268.  
  269. def Login():
  270. global nameEL
  271. global pwordEL # More globals :D
  272. global rootA
  273.  
  274. rootA = Tk() # This now makes a new window.
  275. rootA.title('Login') # This makes the window title 'login'
  276.  
  277. intruction = Label(rootA, text='Please Login\n') # More labels to tell us what they do
  278. intruction.grid(sticky=E) # Blahdy Blah
  279.  
  280. nameL = Label(rootA, text='Username: ') # More labels
  281. pwordL = Label(rootA, text='Password: ') # ^
  282. nameL.grid(row=1, sticky=W)
  283. pwordL.grid(row=2, sticky=W)
  284.  
  285. nameEL = Entry(rootA) # The entry input
  286. pwordEL = Entry(rootA, show='*')
  287. nameEL.grid(row=1, column=1)
  288. pwordEL.grid(row=2, column=1)
  289.  
  290. loginB = Button(rootA, text='Login', command=CheckLogin) # This makes the login button, which will go to the CheckLogin def.
  291. loginB.grid(columnspan=2, sticky=W)
  292.  
  293. rmuser = Button(rootA, text='Delete User', fg='red', command=DelUser) # This makes the deluser button. blah go to the deluser def.
  294. rmuser.grid(columnspan=2, sticky=W)
  295. rootA.mainloop()
  296.  
  297. def CheckLogin():
  298. with open(creds) as f:
  299. data = f.readlines() # This takes the entire document we put the info into and puts it into the data variable
  300. uname = data[0].rstrip() # Data[0], 0 is the first line, 1 is the second and so on.
  301. pword = data[1].rstrip() # Using .rstrip() will remove the \n (new line) word from before when we input it
  302.  
  303. if nameEL.get() == uname and pwordEL.get() == pword: # Checks to see if you entered the correct data.
  304. time.sleep(3)
  305. TheGame()
  306. sys.exit(thelogin)
  307. else:
  308. r = Tk()
  309. r.title('D:')
  310. r.geometry('150x50')
  311. rlbl = Label(r, text='\n[!] Invalid Login')
  312. rlbl.pack()
  313. r.mainloop()
  314.  
  315. def DelUser():
  316. os.remove(creds) # Removes the file
  317. rootA.destroy() # Destroys the login window
  318. Signup() # And goes back to the start!
  319.  
  320. if os.path.isfile(creds):
  321. Login()
  322. else: # This if else statement checks to see if the file exists. If it does it will go to Login, if not it will go to Signup :)
  323. Signup()
  324.  
  325.  
  326. thelogin()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement