Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from Tkinter import *
- from tkMessageBox import *
- import os
- import random
- Interface = Tk()
- Interface.resizable(0, 0)
- global Vote_Reroll
- def Homepage():
- global Username_Input
- global Password_Input
- Interface.title("Cyber Roll")
- Interface.geometry("400x200")
- Hello = Label(Interface, text="Welcome to Cyber Roll", font="Helvetica 10 bold ")
- Hello.place(x=145, y=5)
- 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=LoginModule)
- Login.place(x=50, y=100)
- Sign_Up = Button(Interface, width=15, text="Sign Up", command = SignUpWindow)
- Sign_Up.place(x=240, y=100)
- def LoginModule():
- CompareUser = Username_Input.get()
- ComparePassword = Password_Input.get()
- OpeningAccount = open('account.txt', 'r')
- Line1 = next(OpeningAccount)
- AccountList = Line1.split(":")
- Line2 = next(OpeningAccount)
- PasswordList = Line2.split(",")
- OpeningAccount.close()
- Counter = 0
- MaxCounter = len(AccountList)
- while (Counter < MaxCounter):
- if (CompareUser == AccountList[Counter] and ComparePassword == PasswordList[Counter]):
- MenuModule()
- Counter = MaxCounter + 1
- else:
- Counter += 1
- if (Counter == MaxCounter):
- showinfo("System Info", "No such account! Please try again!")
- Homepage()
- CompareUser = ""
- ComparePassword = ""
- def MenuModule():
- 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")
- Menu.resizable(0, 0)
- 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=CheckSum)
- Roll.place(x=100, y=140)
- def PickingRestaurant():
- global Selected
- global SelectedRestaurantAddress
- if Halal_V.get() == 1 and NonHalal_V.get() == 0:
- HalalList = open("halal.txt", 'r')
- HalalLine1 = next(HalalList) # cause we only splitting line 1, important note
- HalalRestaurant = HalalLine1.split(":")
- Selected = random.choice(HalalRestaurant)
- HalalList.close()
- HalalList = open("halal.txt", 'r')
- next(HalalList)
- for iterator in HalalList:
- RestaurantInfo = iterator.split(":")
- RestaurantName = RestaurantInfo[0]
- RestaurantAddress = RestaurantInfo[1]
- if (RestaurantName == Selected):
- SelectedRestaurantAddress = RestaurantAddress
- Printing()
- else:
- pass
- elif NonHalal_V.get() == 1 and Halal_V.get() == 0:
- NonHalalList = open("nonhalal.txt", 'r')
- NonHalalLine1 = next(NonHalalList) # cause we only splitting line 1, important note
- NonHalalRestaurant = NonHalalLine1.split(":")
- Selected = random.choice(NonHalalRestaurant)
- NonHalalList.close()
- NonHalalList = open("nonhalal.txt", 'r')
- next(NonHalalList)
- for iterator in NonHalalList:
- RestaurantInfo = iterator.split(":")
- RestaurantName = RestaurantInfo[0]
- RestaurantAddress = RestaurantInfo[1]
- if (RestaurantName == Selected):
- SelectedRestaurantAddress = RestaurantAddress
- Printing()
- else:
- pass
- elif NonHalal_V.get() == 1 and Halal_V.get() == 1:
- NonHalalList = open("nonhalal.txt", 'r')
- HalalList = open("halal.txt", 'r')
- NonHalalLine1 = next(NonHalalList) # cause we only splitting line 1, important note
- HalalLine1 = next(HalalList) # cause we only splitting line 1, important note
- NonHalalRestaurant = NonHalalLine1.split(":")
- HalalRestaurant = HalalLine1.split(":")
- AllRestaurant = HalalRestaurant + NonHalalRestaurant # Combine
- Selected = random.choice(AllRestaurant) # randomg selecting
- NonHalalList.close() # closing these two to avoid any trouble on reading again
- HalalList.close() # closing these two to avoid any trouble on reading again.
- NonHalalList = open("nonhalal.txt", 'r')
- HalalList = open("halal.txt", 'r')
- next(NonHalalList)
- next(HalalList)
- for iterator in NonHalalList:
- NonHalalRestaurantInfo = iterator.split(":")
- if Selected == NonHalalRestaurantInfo[0]:
- SelectedRestaurantAddress = NonHalalRestaurantInfo[1]
- else:
- pass
- for iterator in HalalList:
- HalalRestaurantInfo = iterator.split(":")
- if Selected == HalalRestaurantInfo[0]:
- SelectedRestaurantAddress = HalalRestaurantInfo[1]
- else:
- pass
- Printing()
- else:
- showinfo("System Info", "Warning: System detected you pick nothing ! Please pick so")
- def Printing():
- global Menu2
- global Vote_Reroll
- global RestaurantInfo
- Menu2 = Toplevel()
- Menu2.title("Cyber Roll")
- Menu2.geometry("500x200")
- Menu2.resizable(0, 0)
- Menu.withdraw()
- 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_Reroll = Entry(Menu2, width=45)
- Vote_Reroll.place(x=180, y=70)
- RestaurantInfoButton = Button(Menu2, text="Resturant\n info", width=15, command=PrintRestInfoModule)
- RestaurantInfoButton.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 CheckSum():
- global SumPeople
- try:
- if len(Ppl_Num_Input.get()) == 0:
- showinfo("System Info", "Warning: Please insert sommething")
- elif int(Ppl_Num_Input.get()) < 1:
- showinfo("System Info", "Warning: No negative number is allowed")
- else:
- PickingRestaurant()
- except ValueError:
- showinfo("System Info", "Warning: System detected you entered something strange!\nOnly integer is allowed!")
- def PrintRestInfoModule():
- Restaurant_Info = Toplevel()
- Restaurant_Info.title("Cyber Roll - Restaurant Info")
- Restaurant_Info.geometry("850x100")
- Restaurant_Info.resizable(0, 0)
- 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)
- Address = Label(Restaurant_Info, text="Restaurant Address : ")
- Address.place(x=20, y=50)
- Res_Address = Label(Restaurant_Info, text=SelectedRestaurantAddress)
- Res_Address.place(x=160, y=50)
- def ReRoll():
- try:
- TotalNumber = int(str(Ppl_Num_Input.get()))
- TotalNumber=TotalNumber/2
- VoteReRoll = int(str(Vote_Reroll.get()))
- if VoteReRoll<0:
- showinfo("System Info", "Warning: No negative number is allowed")
- elif (VoteReRoll > TotalNumber):
- Menu2.withdraw()
- PickingRestaurant()
- except ValueError:
- showinfo("System Info", "Warning: System detected you entered something strange!\nPlease insert again and only integer are allowed!")
- def Sign_Up_Module():
- NewUser = Reg_Username_Input.get()
- Password = Reg_Password_Input.get()
- ConfirmPass = Reg_Passconfirm_Input.get()
- AccountList = open("account.txt","r")
- AccLine1 = next(AccountList)
- UserList = AccLine1.split(":")
- PasswordList = AccLine2.split(",")
- ListCounter = len(UserList)
- Exist = 0
- for i in range(0,ListCounter,1):
- if UserList[i] == NewUser:
- showinfo("System Info", "Warning: Username exist! Please try again.")
- Exist = 1
- else:
- pass
- AccountList.close()
- if i == ListCounter-1 and Exist == 0:
- if Password == ConfirmPass:
- pass
- elif (Password != ConfirmPass):
- showinfo("System Info", "Sorry, the password is not same as confirm password.\nPlease try again.")
- else:
- pass
- def SignUpWindow():
- global Reg_Username_Input
- global Reg_Password_Input
- global Reg_Passconfirm_Input
- Interface.withdraw()
- SignUp = Toplevel()
- SignUp.title("Cyber Roll")
- SignUp.geometry("450x200")
- SignUp.resizable(0, 0)
- Greeting = Label(SignUp, text="Cyber Roll - Sign Up")
- Greeting.place(x=20, y=0)
- Reg_Username = Label(SignUp, text="Username: ")
- Reg_Username.place(x=20, y=40)
- Reg_Username_Input = Entry(SignUp, width=45)
- Reg_Username_Input.place(x=140, y=40)
- Reg_Password = Label(SignUp, text="Password: ")
- Reg_Password.place(x=20, y=70)
- Reg_Password_Input = Entry(SignUp, width=45, show="*")
- Reg_Password_Input.place(x=140, y=70)
- Reg_Passconfirm = Label(SignUp, text="Confirm Password: ")
- Reg_Passconfirm.place(x=20, y=100)
- Reg_Passconfirm_Input = Entry(SignUp, width=45, show="*")
- Reg_Passconfirm_Input.place(x=140, y=100)
- Sign_Up = Button(SignUp, width=15, text="Sign Up", command=Storing)
- Sign_Up.place(x=220, y=130)
- Homepage()
- Interface.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement