Advertisement
Guest User

Untitled

a guest
Jan 15th, 2017
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.65 KB | None | 0 0
  1. from Tkinter import*
  2. from tkMessageBox import*
  3. import os
  4. import os.path
  5. import random
  6. global Selected
  7. Interface = Tk()
  8. Interface.resizable(0,0)
  9.  
  10. Path = "C:\Users\Sam\Desktop\CyberRoll\Account\\account.txt"
  11. HalalPath = "C:\Users\Sam\Desktop\CyberRoll\Restaurant\\halal.txt"
  12. NonHalalPath = "C:\Users\Sam\Desktop\CyberRoll\Restaurant\\nonhalal.txt"
  13.  
  14. def AccountFunc():
  15. CompareUser = username_input.get()
  16. ComparePassword = password_input.get()
  17. AccountList = open(Path, 'r')
  18. SumLines = sum(1 for lines in open(Path))
  19. Counter = 0
  20. for iterator in AccountList:
  21. Counter +=1
  22. Account = iterator.split(":")
  23. User =Account[0]
  24. Pass =Account[1]
  25. if (User == CompareUser and Pass == ComparePassword):
  26. MenuFunc()
  27. break
  28.  
  29. if (ComparePassword =="" and CompareUser == ""):
  30. break
  31.  
  32. if (User != CompareUser or Pass!= ComparePassword and ComparePassword != "" or CompareUser != ""):
  33. if (Counter == SumLines):
  34. showinfo("System Info","Wrong username or password inserted! Pleae enter again.")
  35.  
  36. def SignUpFunc():
  37. AccountList = open(Path, 'r')
  38. NewUser = username_input.get()
  39. Password = password_input.get()
  40. ConfirmPass = passconfirm_input.get()
  41. SumLines = sum(1 for lines in open(Path))
  42. for line in AccountList:
  43. Account = line.split(":")
  44. UserList =Account[0]
  45. print UserList
  46. print "NewUser is" +NewUser
  47. if (UserList == NewUser and NewUser != ""):
  48. NewUser = ""
  49. showinfo ("System Info", "Username exist, please try again!")
  50.  
  51. else:
  52. pass
  53.  
  54. if (UserList!= NewUser and NewUser != ""):
  55. if(Password == ConfirmPass and NewUser != "" and Password != "" and ConfirmPass != ""):
  56. Writing = open(Path, 'a')
  57. Writing.write("\n"+NewUser+":"+ConfirmPass+":")
  58. showinfo ("SystemInfo", "Account register successful !")
  59. Password = ""
  60. ConfirmPass = ""
  61. elif (Password != ConfirmPass):
  62. showinfo ("SystemInfo", "Confirm Password is not the same ! Please try again.")
  63. Password = ""
  64. ConfirmPass = ""
  65.  
  66. def Restaurant_Info():
  67. Restaurant_Info = Toplevel()
  68. Restaurant_Info.title("Cyber Roll - Restaurant Info")
  69. Restaurant_Info.geometry("850x160")
  70.  
  71.  
  72. Res_name = Label (Restaurant_Info,text = "Restaurant Name : ")
  73. Res_name.place(x=20,y=20)
  74.  
  75. Res_info = Label (Restaurant_Info,text = Selected)
  76. Res_info.place(x=160,y=20)
  77.  
  78. Phone = Label (Restaurant_Info,text = "Phone Number : ")
  79. Phone.place(x=20,y=50)
  80.  
  81. Phone_info = Label (Restaurant_Info,text = "012-3456789")
  82. Phone_info.place(x=160,y=50)
  83.  
  84. Address = Label (Restaurant_Info,text = "Restaurant Address : ")
  85. Address.place(x=20,y=80)
  86.  
  87. Res_Address = Label (Restaurant_Info,text = FinalRestaurantAddress)
  88. Res_Address.place(x=160,y=80)
  89.  
  90. def SignUp():
  91. SignUp = Toplevel()
  92. SignUp.title("Cyber Roll")
  93. SignUp.geometry("450x200")
  94.  
  95. Greeting=Label(SignUp,text="Cyber Roll - Sign Up")
  96. Greeting.place(x=20,y=0)
  97.  
  98. username = Label(SignUp,text="Username: ")
  99. username.place(x=20,y=40)
  100.  
  101. global username_input
  102. username_input = Entry(SignUp,width=45)
  103. username_input.place(x=140,y=40)
  104.  
  105. password = Label(SignUp,text="Password: ")
  106. password.place(x=20,y=70)
  107.  
  108. global password_input
  109. password_input = Entry(SignUp,width=45,show="*")
  110. password_input.place(x=140,y=70)
  111.  
  112. passconfirm = Label(SignUp,text="Confirm Password: ")
  113. passconfirm.place(x=20,y=100)
  114.  
  115. global passconfirm_input
  116. passconfirm_input = Entry(SignUp,width=45,show="*")
  117. passconfirm_input.place(x=140,y=100)
  118.  
  119. sign_up = Button(SignUp,width=15,text="Sign Up",command=SignUpFunc)
  120. sign_up.place(x=220,y=130)
  121.  
  122. def MenuFunc():
  123. global halal_v
  124. global nonhalal_v
  125. global ppl_num_input
  126. global Menu
  127.  
  128. halal_v = IntVar()
  129. nonhalal_v = IntVar()
  130. Interface.withdraw()
  131. Menu = Toplevel()
  132. Menu.title("Cyber Roll")
  133. Menu.geometry("300x200")
  134.  
  135. Title = Label(Menu,text="Cyber Roll - Menu")
  136. Title.place(x=20,y=0)
  137.  
  138. halal = Checkbutton(Menu,text="Halal",variable=halal_v)
  139. halal.place(x=20,y=40)
  140.  
  141. non_halal = Checkbutton(Menu,text="Non - Halal",variable=nonhalal_v)
  142. non_halal.place(x=20,y=70)
  143.  
  144. ppl_num=Label(Menu,text="Number of People: ")
  145. ppl_num.place(x=20,y=100)
  146.  
  147. ppl_num_input = Entry(Menu,width=20)
  148. ppl_num_input.place(x=130,y=100)
  149.  
  150.  
  151. Roll = Button(Menu,width=15,text="Roll",command=PickingRestaurant)
  152. Roll.place(x=100,y=140)
  153.  
  154. def PickingRestaurant():
  155. if halal_v.get()==1:
  156. Halal()
  157.  
  158. else:
  159. NonHalal()
  160.  
  161. def Halal():
  162. global Selected
  163. global FinalRestaurantAddress
  164. HalalList = open(HalalPath, 'r')
  165. HalalLine = next(HalalList)
  166. RestaurantName = HalalLine.split(":")
  167. Selected = random.choice(RestaurantName)
  168. RestaurantInfo = open(HalalPath, 'r')
  169. next(RestaurantInfo)
  170. for iterator in RestaurantInfo:
  171. RestaurantInfoNew = iterator.split(":")
  172. RestaurantName = RestaurantInfoNew[0]
  173. RestaurantAddress = RestaurantInfoNew[1]
  174. if (RestaurantName == Selected):
  175. FinalRestaurantAddress = RestaurantAddress
  176. Menu2Func()
  177. else:
  178. pass
  179.  
  180. def NonHalal():
  181. global Selected
  182. global FinalRestaurantAddress
  183. NonHalalList = open(NonHalalPath, 'r')
  184. NonHalalLine =next(NonHalalList)
  185. RestaurantName = NonHalalLine.split(":")
  186. Selected = random.choice(RestaurantName)
  187. RestaurantInfo = open(NonHalalPath, 'r')
  188. next(RestaurantInfo)
  189. for iterator in RestaurantInfo:
  190. RestaurantInfoNew = iterator.split(":")
  191. RestaurantName = RestaurantInfoNew[0]
  192. RestaurantAddress = RestaurantInfoNew[1]
  193. if (RestaurantName == Selected):
  194. FinalRestaurantAddress = RestaurantAddress
  195. Menu2Func()
  196. else:
  197. pass
  198.  
  199. def Menu2Func():
  200. global Selected
  201. global Vote_input
  202. global Menu2
  203. Menu2 = Toplevel()
  204. Menu2.title("Cyber Roll")
  205. Menu2.geometry("500x200")
  206.  
  207. title = Label(Menu2,text="Cyber Roll - Menu")
  208. title.place(x=20,y=0)
  209.  
  210. Rec_Restaurant = Label(Menu2,text="Recommended Restaurant: ")
  211. Rec_Restaurant.place(x=20,y=40)
  212.  
  213. Rec_Restaurant_Label =Label(Menu2,text=Selected)
  214. Rec_Restaurant_Label.place(x=260,y=40)
  215.  
  216. Vote = Label(Menu2,text="Vote to Reroll: ")
  217. Vote.place(x=20,y=70)
  218.  
  219. Vote_input = Entry(Menu2,width=45)
  220. Vote_input.place(x=180,y=70)
  221.  
  222. Restaurantinfo = Button(Menu2,text="Resturant\n info",width = 15,command=Restaurant_Info)
  223. Restaurantinfo.place(x=80,y=120)
  224.  
  225. Reroll = Button(Menu2,text="Re-Roll\n",width = 15,command=ReRoll)
  226. Reroll.place(x=200,y=120)
  227.  
  228. Accept = Button(Menu2,text="Accept\n",width = 15,command=Interface.destroy)
  229. Accept.place(x=320,y=120)
  230.  
  231. def ReRoll():
  232. try:
  233. SumPeople = int(str(ppl_num_input.get()))
  234. VoteReRoll = int(str(Vote_input.get()))
  235. VoteReRoll = int(VoteReRoll)
  236. SumPeople = int(SumPeople/2)
  237. if (VoteReRoll>SumPeople):
  238. Menu2.withdraw()
  239. PickingRestaurant()
  240. else:
  241. showinfo("System Info","Seems like people like the restaurant system recommended!")
  242.  
  243. except ValueError:
  244. VoteReRoll =Vote_input.get()
  245. SumPeople =ppl_num_input.get()
  246. if (ValueSum == ValueVoteReRoll):
  247. Menu2.withdraw()
  248. PickingRestaurant()
  249. else:
  250. showinfo("System Info","Please insert something!")
  251.  
  252. def Login():
  253. global username_input
  254. global password_input
  255. Interface.title ("Cyber Roll")
  256. Interface.geometry("400x200")
  257.  
  258. Hello=Label(Interface,text="Welcome to Cyber Roll")
  259. Hello.place(x=160,y=0)
  260.  
  261. username = Label(Interface,text="Username: ")
  262. username.place(x=20,y=40)
  263.  
  264. username_input = Entry(Interface,width=45)
  265. username_input.place(x=100,y=40)
  266.  
  267. password = Label(Interface,text="Password: ")
  268. password.place(x=20,y=70)
  269.  
  270. password_input = Entry(Interface,width=45,show="*")
  271. password_input.place(x=100,y=70)
  272.  
  273. login = Button(Interface,width=15,text="Login",command=AccountFunc)
  274. login.place(x=70,y=100)
  275.  
  276. sign_up = Button(Interface,width=15,text="Sign Up",command=SignUp)
  277. sign_up.place(x=270,y=100)
  278.  
  279. Login()
  280. Interface.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement