Advertisement
Guest User

Untitled

a guest
Feb 13th, 2017
166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.67 KB | None | 0 0
  1. from Tkinter import*
  2. from tkMessageBox import*
  3. import os
  4. import random
  5. Interface = Tk()
  6. Interface.resizable(0,0)
  7.  
  8. global Vote_Reroll
  9.  
  10. def Homepage():
  11. global Username_Input
  12. global Password_Input
  13. Interface.title ("Cyber Roll")
  14. Interface.geometry("400x200")
  15.  
  16. Hello=Label(Interface,text="Welcome to Cyber Roll",font = "Helvetica 10 bold ")
  17. Hello.place(x=145,y=5)
  18.  
  19. Username = Label(Interface,text="Username: ")
  20. Username.place(x=20,y=40)
  21.  
  22. Username_Input = Entry(Interface,width=45)
  23. Username_Input.place(x=100,y=40)
  24.  
  25. Password = Label(Interface,text="Password: ")
  26. Password.place(x=20,y=70)
  27.  
  28. Password_Input = Entry(Interface,width=45,show="*")
  29. Password_Input.place(x=100,y=70)
  30.  
  31. Login = Button(Interface,width=15,text="Login",command=LoginModule)
  32. Login.place(x=50,y=100)
  33.  
  34. Sign_Up = Button(Interface,width=15,text="Sign Up",command=SignUpModule)
  35. Sign_Up.place(x=240,y=100)
  36.  
  37. def LoginModule():
  38. CompareUser = Username_Input.get()
  39. ComparePassword = Password_Input.get()
  40. OpeningAccount = open('account.txt', 'r')
  41. Line1 = next(OpeningAccount)
  42. AccountList = Line1.split(":")
  43. Line2 = next(OpeningAccount)
  44. PasswordList = Line2.split(",")
  45. OpeningAccount.close()
  46. Counter = 0
  47. MaxCounter = len(AccountList)
  48. while (Counter < MaxCounter):
  49. if (CompareUser == AccountList[Counter] and ComparePassword == PasswordList[Counter]):
  50. MenuModule()
  51. Counter = MaxCounter+1
  52.  
  53. else:
  54. Counter+=1
  55. if (Counter == MaxCounter):
  56. showinfo ("System Info", "No such account! Please try again!")
  57. Homepage()
  58. CompareUser = ""
  59. ComparePassword = ""
  60.  
  61. def MenuModule():
  62. global Halal_V
  63. global NonHalal_V
  64. global Ppl_Num_Input
  65. global Menu
  66.  
  67. Halal_V = IntVar()
  68. NonHalal_V = IntVar()
  69. Interface.withdraw()
  70. Menu = Toplevel()
  71. Menu.title("Cyber Roll")
  72. Menu.geometry("300x200")
  73. Menu.resizable(0,0)
  74.  
  75. Title = Label(Menu,text="Cyber Roll - Menu")
  76. Title.place(x=20,y=0)
  77.  
  78. Halal = Checkbutton(Menu,text="Halal",variable=Halal_V)
  79. Halal.place(x=20,y=40)
  80.  
  81. Non_Halal = Checkbutton(Menu,text="Non - Halal",variable=NonHalal_V)
  82. Non_Halal.place(x=20,y=70)
  83.  
  84. Ppl_Num=Label(Menu,text="Number of People: ")
  85. Ppl_Num.place(x=20,y=100)
  86.  
  87. Ppl_Num_Input = Entry(Menu,width=20)
  88. Ppl_Num_Input.place(x=130,y=100)
  89.  
  90.  
  91. Roll = Button(Menu,width=15,text="Roll",command=CheckSum)
  92. Roll.place(x=100,y=140)
  93.  
  94. def PickingRestaurant():
  95. global Selected
  96. global SelectedRestaurantAddress
  97.  
  98. if Halal_V.get()==1 and NonHalal_V.get()==0:
  99. HalalList = open("halal.txt", 'r')
  100. HalalLine1 = next(HalalList) #cause we only splitting line 1, important note
  101. HalalRestaurant = HalalLine1.split(":")
  102. Selected = random.choice(HalalRestaurant)
  103. HalalList.close()
  104.  
  105. HalalList = open("halal.txt", 'r')
  106. next(HalalList)
  107. for iterator in HalalList:
  108. RestaurantInfo = iterator.split(":")
  109. RestaurantName = RestaurantInfo[0]
  110. RestaurantAddress = RestaurantInfo[1]
  111. if (RestaurantName == Selected):
  112. SelectedRestaurantAddress = RestaurantAddress
  113. Printing()
  114.  
  115. else:
  116. pass
  117.  
  118. elif NonHalal_V.get() == 1 and Halal_V.get()==0:
  119. NonHalalList = open("nonhalal.txt", 'r')
  120. NonHalalLine1 = next(NonHalalList) # cause we only splitting line 1, important note
  121. NonHalalRestaurant = NonHalalLine1.split(":")
  122. Selected = random.choice(NonHalalRestaurant)
  123. NonHalalList.close()
  124.  
  125. NonHalalList = open("nonhalal.txt", 'r')
  126. next(NonHalalList)
  127. for iterator in NonHalalList:
  128. RestaurantInfo = iterator.split(":")
  129. print RestaurantInfo[0]
  130. RestaurantName = RestaurantInfo[0]
  131. RestaurantAddress = RestaurantInfo[1]
  132. if (RestaurantName == Selected):
  133. SelectedRestaurantAddress = RestaurantAddress
  134. Printing()
  135.  
  136. else:
  137. pass
  138.  
  139. elif NonHalal_V.get() == 1 and Halal_V.get()==1:
  140.  
  141. NonHalalList = open("nonhalal.txt", 'r')
  142. HalalList = open("halal.txt", 'r')
  143. NonHalalLine1 = next(NonHalalList) # cause we only splitting line 1, important note
  144. HalalLine1 = next(HalalList) # cause we only splitting line 1, important note
  145. NonHalalRestaurant = NonHalalLine1.split(":")
  146. HalalRestaurant = HalalLine1.split(":")
  147. AllRestaurant = HalalRestaurant + NonHalalRestaurant # Combine
  148. Selected = random.choice(AllRestaurant) # randomg selecting
  149. NonHalalList.close() # closing these two to avoid any trouble on reading again
  150. HalalList.close() # closing these two to avoid any trouble on reading again.
  151.  
  152. NonHalalList = open("nonhalal.txt", 'r')
  153. HalalList = open("halal.txt", 'r')
  154. next(NonHalalList)
  155. next(HalalList)
  156. for iterator in NonHalalList:
  157. NonHalalRestaurantInfo = iterator.split(":")
  158. if Selected == NonHalalRestaurantInfo[0]:
  159. SelectedRestaurantAddress= NonHalalRestaurantInfo[1]
  160. else:
  161. pass
  162.  
  163.  
  164. for iterator in HalalList:
  165. HalalRestaurantInfo = iterator.split(":")
  166. if Selected == HalalRestaurantInfo[0]:
  167. SelectedRestaurantAddress = HalalRestaurantInfo[1]
  168. else:
  169. pass
  170.  
  171. Printing()
  172.  
  173. else:
  174. showinfo("System Info", "Warning: System detected you pick nothing ! Please pick so")
  175.  
  176. def Printing():
  177. global Menu2
  178. global Vote_Reroll
  179. global RestaurantInfo
  180. Menu2 = Toplevel()
  181. Menu2.title("Cyber Roll")
  182. Menu2.geometry("500x200")
  183. Menu2.resizable(0,0)
  184. Menu.withdraw()
  185.  
  186. title = Label(Menu2, text="Cyber Roll - Menu")
  187. title.place(x=20, y=0)
  188.  
  189. Rec_Restaurant = Label(Menu2, text="Recommended Restaurant: ")
  190. Rec_Restaurant.place(x=20, y=40)
  191.  
  192. Rec_Restaurant_Label = Label(Menu2, text=Selected)
  193. Rec_Restaurant_Label.place(x=260, y=40)
  194.  
  195. Vote = Label(Menu2, text="Vote to Reroll: ")
  196. Vote.place(x=20, y=70)
  197.  
  198. Vote_Reroll = Entry(Menu2, width=45)
  199. Vote_Reroll.place(x=180, y=70)
  200.  
  201. RestaurantInfoButton = Button(Menu2, text="Resturant\n info", width=15, command=PrintRestInfoModule)
  202. RestaurantInfoButton.place(x=80, y=120)
  203.  
  204. Reroll = Button(Menu2, text="Re-Roll\n", width=15, command=CheckSum)
  205. Reroll.place(x=200, y=120)
  206.  
  207. Accept = Button(Menu2, text="Accept\n", width=15, command=Interface.destroy)
  208. Accept.place(x=320, y=120)
  209.  
  210. def CheckSum():
  211. global SumPeople
  212. try:
  213. if len(Ppl_Num_Input.get()) == 0:
  214. showinfo("System Info", "Warning: Please insert sommething")
  215.  
  216. elif int(Ppl_Num_Input.get()) < 1:
  217. showinfo("System Info", "Warning: No negative number is allowed")
  218.  
  219. else:
  220. print int(Ppl_Num_Input.get())
  221. PickingRestaurant()
  222.  
  223. except ValueError:
  224. showinfo("System Info", "Warning: System detected you entered something strange!\nOnly integer is allowed!")
  225.  
  226.  
  227. def PrintRestInfoModule():
  228. Restaurant_Info = Toplevel()
  229. Restaurant_Info.title("Cyber Roll - Restaurant Info")
  230. Restaurant_Info.geometry("850x100")
  231. Restaurant_Info.resizable(0,0)
  232.  
  233. Res_name = Label(Restaurant_Info, text="Restaurant Name : ")
  234. Res_name.place(x=20, y=20)
  235.  
  236. Res_info = Label(Restaurant_Info, text=Selected)
  237. Res_info.place(x=160, y=20)
  238.  
  239. Address = Label(Restaurant_Info, text="Restaurant Address : ")
  240. Address.place(x=20, y=50)
  241.  
  242. Res_Address = Label(Restaurant_Info, text=SelectedRestaurantAddress)
  243. Res_Address.place(x=160, y=50)
  244.  
  245. def ReRoll():
  246. try:
  247. SumPeople = int(SumPeople/2)
  248. VoteReRoll = int(Vote_Reroll.get())
  249.  
  250. if len(Vote_Reroll.get()) == 0:
  251. showinfo("System Info", "Warning: The input is empty ! Please input something")
  252.  
  253. elif int(Vote_Reroll.get()) <= 1:
  254. showinfo("System Info", "Warning: No negative number is allowed")
  255.  
  256. elif (VoteReRoll>SumPeople):
  257. ReRoll.withdraw()
  258. PickingRestaurant()
  259.  
  260. else:
  261. pass
  262.  
  263. except ValueError:
  264. VoteReRoll =Vote_Reroll.get()
  265. SumPeople =Ppl_Num_Input.get()
  266. showinfo("System Info", "Warning: System detected you entered something strange!\nOnly integer is allowed!")
  267.  
  268. def SignUpWindow():
  269. SignUp = Toplevel()
  270. SignUp.title("Cyber Roll")
  271. SignUp.geometry("450x200")
  272. SignUp.resizable(0,0)
  273.  
  274. Greeting=Label(SignUp,text="Cyber Roll - Sign Up")
  275. Greeting.place(x=20,y=0)
  276.  
  277. Reg_Username = Label(SignUp,text="Username: ")
  278. Reg_Username.place(x=20,y=40)
  279.  
  280. global Reg_Username_Input
  281. Reg_Username_Input = Entry(SignUp,width=45)
  282. Reg_Username_Input.place(x=140,y=40)
  283.  
  284. Reg_Password = Label(SignUp,text="Password: ")
  285. Reg_Password.place(x=20,y=70)
  286.  
  287. global Reg_Password_Input
  288. Reg_Password_Input = Entry(SignUp,width=45,show="*")
  289. Reg_Password_Input.place(x=140,y=70)
  290.  
  291. Reg_Passconfirm = Label(SignUp,text="Confirm Password: ")
  292. Reg_Passconfirm.place(x=20,y=100)
  293.  
  294. global Reg_Passconfirm_Input
  295. Reg_Passconfirm_Input = Entry(SignUp,width=45,show="*")
  296. Reg_Passconfirm_Input.place(x=140,y=100)
  297.  
  298. Sign_Up = Button(SignUp,width=15,text="Sign Up",command=Sign_Up_Module)
  299. Sign_Up.place(x=220,y=130)
  300.  
  301. Homepage()
  302. Interface.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement