Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from Tkinter import*
- from tkMessageBox import*
- import os
- import os.path
- import random
- global Selected
- Interface = Tk()
- Interface.resizable(0,0)
- Path = "C:\Users\Sam\Desktop\CyberRoll\Account\\account.txt"
- HalalPath = "C:\Users\Sam\Desktop\CyberRoll\Restaurant\\halal.txt"
- NonHalalPath = "C:\Users\Sam\Desktop\CyberRoll\Restaurant\\nonhalal.txt"
- def AccountFunc():
- CompareUser = username_input.get()
- ComparePassword = password_input.get()
- AccountList = open(Path, 'r')
- SumLines = sum(1 for lines in open(Path))
- Counter = 0
- for iterator in AccountList:
- Counter +=1
- Account = iterator.split(":")
- User =Account[0]
- Pass =Account[1]
- if (User == CompareUser and Pass == ComparePassword):
- MenuFunc()
- break
- if (ComparePassword =="" and CompareUser == ""):
- break
- if (User != CompareUser or Pass!= ComparePassword and ComparePassword != "" or CompareUser != ""):
- if (Counter == SumLines):
- showinfo("System Info","Wrong username or password inserted! Pleae enter again.")
- def SignUpFunc():
- AccountList = open(Path, 'r')
- NewUser = username_input.get()
- Password = password_input.get()
- ConfirmPass = passconfirm_input.get()
- SumLines = sum(1 for lines in open(Path))
- for line in AccountList:
- Account = line.split(":")
- UserList =Account[0]
- print UserList
- print "NewUser is" +NewUser
- if (UserList == NewUser and NewUser != ""):
- NewUser = ""
- showinfo ("System Info", "Username exist, please try again!")
- else:
- pass
- if (UserList!= NewUser and NewUser != ""):
- if(Password == ConfirmPass and NewUser != "" and Password != "" and ConfirmPass != ""):
- Writing = open(Path, 'a')
- Writing.write("\n"+NewUser+":"+ConfirmPass+":")
- showinfo ("SystemInfo", "Account register successful !")
- Password = ""
- ConfirmPass = ""
- elif (Password != ConfirmPass):
- showinfo ("SystemInfo", "Confirm Password is not the same ! Please try again.")
- Password = ""
- ConfirmPass = ""
- def Restaurant_Info():
- Restaurant_Info = Toplevel()
- Restaurant_Info.title("Cyber Roll - Restaurant Info")
- Restaurant_Info.geometry("850x160")
- Res_name = Label (Restaurant_Info,text = "Restaurant Name : ")
- Res_name.place(x=20,y=20)
- Res_info = Label (Restaurant_Info,text = Selected)
- Res_info.place(x=160,y=20)
- Phone = Label (Restaurant_Info,text = "Phone Number : ")
- Phone.place(x=20,y=50)
- Phone_info = Label (Restaurant_Info,text = "012-3456789")
- Phone_info.place(x=160,y=50)
- Address = Label (Restaurant_Info,text = "Restaurant Address : ")
- Address.place(x=20,y=80)
- Res_Address = Label (Restaurant_Info,text = FinalRestaurantAddress)
- Res_Address.place(x=160,y=80)
- def SignUp():
- SignUp = Toplevel()
- SignUp.title("Cyber Roll")
- SignUp.geometry("450x200")
- Greeting=Label(SignUp,text="Cyber Roll - Sign Up")
- Greeting.place(x=20,y=0)
- username = Label(SignUp,text="Username: ")
- username.place(x=20,y=40)
- global username_input
- username_input = Entry(SignUp,width=45)
- username_input.place(x=140,y=40)
- password = Label(SignUp,text="Password: ")
- password.place(x=20,y=70)
- global password_input
- password_input = Entry(SignUp,width=45,show="*")
- password_input.place(x=140,y=70)
- passconfirm = Label(SignUp,text="Confirm Password: ")
- passconfirm.place(x=20,y=100)
- global passconfirm_input
- passconfirm_input = Entry(SignUp,width=45,show="*")
- passconfirm_input.place(x=140,y=100)
- sign_up = Button(SignUp,width=15,text="Sign Up",command=SignUpFunc)
- sign_up.place(x=220,y=130)
- def MenuFunc():
- global halal_v
- global nonhalal_v
- global ppl_num_input
- global Menu
- halal_v = IntVar()
- nonhalal_v = IntVar()
- Interface.withdraw()
- Menu = Toplevel()
- Menu.title("Cyber Roll")
- Menu.geometry("300x200")
- Title = Label(Menu,text="Cyber Roll - Menu")
- Title.place(x=20,y=0)
- halal = Checkbutton(Menu,text="Halal",variable=halal_v)
- halal.place(x=20,y=40)
- non_halal = Checkbutton(Menu,text="Non - Halal",variable=nonhalal_v)
- non_halal.place(x=20,y=70)
- ppl_num=Label(Menu,text="Number of People: ")
- ppl_num.place(x=20,y=100)
- ppl_num_input = Entry(Menu,width=20)
- ppl_num_input.place(x=130,y=100)
- Roll = Button(Menu,width=15,text="Roll",command=PickingRestaurant)
- Roll.place(x=100,y=140)
- def PickingRestaurant():
- if halal_v.get()==1:
- Halal()
- else:
- NonHalal()
- def Halal():
- global Selected
- global FinalRestaurantAddress
- HalalList = open(HalalPath, 'r')
- HalalLine = next(HalalList)
- RestaurantName = HalalLine.split(":")
- Selected = random.choice(RestaurantName)
- RestaurantInfo = open(HalalPath, 'r')
- next(RestaurantInfo)
- for iterator in RestaurantInfo:
- RestaurantInfoNew = iterator.split(":")
- RestaurantName = RestaurantInfoNew[0]
- RestaurantAddress = RestaurantInfoNew[1]
- if (RestaurantName == Selected):
- FinalRestaurantAddress = RestaurantAddress
- Menu2Func()
- else:
- pass
- def NonHalal():
- global Selected
- global FinalRestaurantAddress
- NonHalalList = open(NonHalalPath, 'r')
- NonHalalLine =next(NonHalalList)
- RestaurantName = NonHalalLine.split(":")
- Selected = random.choice(RestaurantName)
- RestaurantInfo = open(NonHalalPath, 'r')
- next(RestaurantInfo)
- for iterator in RestaurantInfo:
- RestaurantInfoNew = iterator.split(":")
- RestaurantName = RestaurantInfoNew[0]
- RestaurantAddress = RestaurantInfoNew[1]
- if (RestaurantName == Selected):
- FinalRestaurantAddress = RestaurantAddress
- Menu2Func()
- else:
- pass
- def Menu2Func():
- global Selected
- global Vote_input
- global Menu2
- Menu2 = Toplevel()
- Menu2.title("Cyber Roll")
- Menu2.geometry("500x200")
- title = Label(Menu2,text="Cyber Roll - Menu")
- title.place(x=20,y=0)
- Rec_Restaurant = Label(Menu2,text="Recommended Restaurant: ")
- Rec_Restaurant.place(x=20,y=40)
- Rec_Restaurant_Label =Label(Menu2,text=Selected)
- Rec_Restaurant_Label.place(x=260,y=40)
- Vote = Label(Menu2,text="Vote to Reroll: ")
- Vote.place(x=20,y=70)
- Vote_input = Entry(Menu2,width=45)
- Vote_input.place(x=180,y=70)
- Restaurantinfo = Button(Menu2,text="Resturant\n info",width = 15,command=Restaurant_Info)
- Restaurantinfo.place(x=80,y=120)
- Reroll = Button(Menu2,text="Re-Roll\n",width = 15,command=ReRoll)
- Reroll.place(x=200,y=120)
- Accept = Button(Menu2,text="Accept\n",width = 15,command=Interface.destroy)
- Accept.place(x=320,y=120)
- def ReRoll():
- try:
- SumPeople = int(str(ppl_num_input.get()))
- VoteReRoll = int(str(Vote_input.get()))
- VoteReRoll = int(VoteReRoll)
- SumPeople = int(SumPeople/2)
- if (VoteReRoll>SumPeople):
- Menu2.withdraw()
- PickingRestaurant()
- else:
- showinfo("System Info","Seems like people like the restaurant system recommended!")
- except ValueError:
- VoteReRoll =Vote_input.get()
- SumPeople =ppl_num_input.get()
- if (ValueSum == ValueVoteReRoll):
- Menu2.withdraw()
- PickingRestaurant()
- else:
- showinfo("System Info","Please insert something!")
- def Login():
- global username_input
- global password_input
- Interface.title ("Cyber Roll")
- Interface.geometry("400x200")
- Hello=Label(Interface,text="Welcome to Cyber Roll")
- Hello.place(x=160,y=0)
- username = Label(Interface,text="Username: ")
- username.place(x=20,y=40)
- username_input = Entry(Interface,width=45)
- username_input.place(x=100,y=40)
- password = Label(Interface,text="Password: ")
- password.place(x=20,y=70)
- password_input = Entry(Interface,width=45,show="*")
- password_input.place(x=100,y=70)
- login = Button(Interface,width=15,text="Login",command=AccountFunc)
- login.place(x=70,y=100)
- sign_up = Button(Interface,width=15,text="Sign Up",command=SignUp)
- sign_up.place(x=270,y=100)
- Login()
- Interface.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement