Advertisement
samleews

Untitled

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