Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from tkinter import *
- import tkinter.ttk as ttk
- from globals import *
- import random
- import pickle
- import locale
- locale.setlocale(locale.LC_ALL, 'en_US') #sets locale to US for number formatting
- #universal background, text, button background, button text color
- uni_bg = "gray6"
- uni_fg = "gray90"
- uni_bt_bg = "gray35"
- uni_bt_fg = "black"
- uni_bt_active = "gray45"
- uni_font = "fixedsys"
- gamestate = GameState()
- class MainWin():
- def __init__(self, master):
- self.master = master
- self.master.title("Hacker")
- self.master.geometry("770x520")
- self.master.attributes("-fullscreen", True)
- self.master.configure(background = uni_bg)
- self.master.columnconfigure(0, weight = 1)
- self.master.rowconfigure(0, weight = 1)
- self.master.bind("<F11>", self.toggle_fullscreen)
- self.master.bind("<Escape>", self.end_fullscreen)
- w = self.master.winfo_screenwidth()
- h = self.master.winfo_screenheight()
- try:
- unpickle_users = open("users.pickle", "rb")
- gamestate.user_dict = pickle.load(unpickle_users)
- except:
- pass
- self.main_frame = Frame(self.master, bd = 10, bg = uni_bg)
- self.main_frame.grid()
- self.lbl = Label(self.main_frame, text = "Hacker", font = (uni_font, 36), bg = uni_bg, fg = uni_fg)
- self.lbl.grid(column = 0, row = 0, pady = 10, sticky = "nsew")
- self.login_bt = Button(self.main_frame, text="Login", font = (uni_font, 12), bg = uni_bt_bg, fg = uni_bt_fg, activebackground = uni_bt_active, command = self.login)
- self.login_bt.grid(column = 0, row = 1, padx = 5, pady = 5, sticky = "nsew")
- self.register_bt = Button(self.main_frame, text="Register", font = (uni_font, 12), bg = uni_bt_bg, fg = uni_bt_fg, activebackground = uni_bt_active, command = self.register)
- self.register_bt.grid(column = 0, row = 2, padx = 5, pady = 5, sticky = "nsew")
- self.tutorial_bt = Button(self.main_frame, text="Tutorial", font = (uni_font, 12), bg = uni_bt_bg, fg = uni_bt_fg, activebackground = uni_bt_active, command = self.tutorial)
- self.tutorial_bt.grid(column = 0, row = 3, padx = 5, pady = 5, sticky = "nsew")
- self.quit_bt = Button(self.main_frame, text="Quit", font = (uni_font, 12), bg = uni_bt_bg, fg = uni_bt_fg, activebackground = uni_bt_active, command = self.quit)
- self.quit_bt.grid(column = 0, row = 4, padx = 5, pady = 5, sticky = "nsew")
- def tutorial(self):
- self.main_frame.destroy()
- TutorialWin(self.master)
- def quit(self):
- root.destroy()
- def login(self):
- self.main_frame.destroy()
- LoginWin(self.master)
- def register(self):
- self.main_frame.destroy()
- RegisterWin(self.master)
- def toggle_fullscreen(self, event=None):
- self.state = not self.state # Just toggling the boolean
- self.master.attributes("-fullscreen", self.state)
- return "break"
- def end_fullscreen(self, event=None):
- self.state = False
- self.master.attributes("-fullscreen", False)
- return "break"
- class LoginWin:
- def __init__(self, master):
- self.master = master
- self.master.title("Login")
- self.main_frame = Frame(self.master, bd = 10, bg = uni_bg)
- self.main_frame.grid()
- self.lbl = Label(self.main_frame, text = "Hacker", font = (uni_font, 36), bg = uni_bg, fg = uni_fg)
- self.lbl.grid(column = 0, row = 0, pady = 10, sticky = "nsew")
- self.status = Label(self.main_frame, text = " ", font = (uni_font, 12), bg = uni_bg, fg = uni_fg)
- self.status.grid(row = 5, pady = 10, sticky = "nsew")
- self.name_entry = Entry(self.main_frame, font = (uni_font, 12))
- self.name_entry.insert(END, "Username")
- self.name_entry.grid(row = 1, sticky = "nsew", pady = 10)
- self.pass_entry = Entry(self.main_frame, font = (uni_font, 12))
- self.pass_entry.insert(END, "Password")
- self.pass_entry.grid(row = 2, sticky = "nsew")
- self.enter_bt = Button(self.main_frame, text="Login", font = (uni_font, 12), bg = uni_bt_bg, fg = uni_bt_fg, activebackground = uni_bt_active, command = self.submit)
- self.enter_bt.grid(row = 3, sticky = "nsew", pady = 10)
- self.back_bt = Button(self.main_frame, text="Back", font = (uni_font, 12), bg = uni_bt_bg, fg = uni_bt_fg, activebackground = uni_bt_active, command = self.back)
- self.back_bt.grid(row = 4, sticky = "nsew")
- def submit(self):
- possible_user = self.name_entry.get()
- possible_password = self.pass_entry.get()
- if possible_user in gamestate.user_dict and possible_password == gamestate.user_dict[possible_user]:
- unpickle_user = open(possible_user + "save.pickle", "rb")
- savestate = pickle.load(unpickle_user)
- unpickle_user.close()
- self.main_frame.destroy()
- GameWin(self.master)
- else:
- self.status.configure(text = "Incorrect credentials")
- def back(self):
- self.main_frame.destroy()
- MainWin(self.master)
- class RegisterWin:
- def __init__(self, master):
- self.master = master
- self.master.title("Register")
- self.main_frame = Frame(self.master, bd = 10, bg = uni_bg)
- self.main_frame.grid()
- self.lbl = Label(self.main_frame, text = "Hacker", font = (uni_font, 36), bg = uni_bg, fg = uni_fg)
- self.lbl.grid(column = 0, row = 0, pady = 10, sticky = "nsew")
- self.status = Label(self.main_frame, text = " ", font = (uni_font, 12), bg = uni_bg, fg = uni_fg)
- self.status.grid(row = 5, pady = 10, sticky = "nsew")
- self.name_entry = Entry(self.main_frame, font = (uni_font, 12))
- self.name_entry.insert(END, "Username")
- self.name_entry.grid(row = 1, sticky = "nsew", pady = 10)
- self.pass_entry = Entry(self.main_frame, font = (uni_font, 12))
- self.pass_entry.insert(END, "Password")
- self.pass_entry.grid(row = 2, sticky = "nsew")
- self.enter_bt = Button(self.main_frame, text="Register", font = (uni_font, 12), bg = uni_bt_bg, fg = uni_bt_fg, activebackground = uni_bt_active, command = self.submit)
- self.enter_bt.grid(row = 3, sticky = "nsew", pady = 10)
- self.back_bt = Button(self.main_frame, text="Back", font = (uni_font, 12), bg = uni_bt_bg, fg = uni_bt_fg, activebackground = uni_bt_active, command = self.back)
- self.back_bt.grid(row = 4, sticky = "nsew")
- def submit(self):
- possible_user = self.name_entry.get()
- possible_password = self.pass_entry.get()
- if possible_user in gamestate.user_dict and possible_password == gamestate.user_dict[possible_user]:
- self.status.configure(text = "Username already exists!")
- else:
- gamestate.user_dict[possible_user] = possible_password
- self.status.configure(text = "Registration successful!")
- pickling_user_data = open(possible_user + "save.pickle","wb")
- pickle.dump(gamestate, pickling_user_data)
- pickling_user_data.close()
- pickling_users = open("users.pickle", "wb") # saving list of all users
- pickle.dump(gamestate.user_dict, pickling_users)
- pickling_users.close()
- def back(self):
- self.main_frame.destroy()
- MainWin(self.master)
- class TutorialWin:
- def __init__(self, master):
- self.master = master
- self.master.title("Tutorial")
- self.main_frame = Frame(self.master, bd = 10, bg = uni_bg)
- self.main_frame.grid()
- self.text = Text(self.main_frame, font = (uni_font, 12), wrap = WORD, bg = uni_bg, fg = uni_fg, highlightbackground = uni_fg, highlightthickness = 3)
- self.text.grid(row = 0)
- self.text.insert(END, ("Welcome to Hacker! To start, register a username and password and login. You can view a list of commands at any time by typing 'help' into you terminal at the bottom left of the screen. \n" \
- "\nThe prompt in the bottom left of the terminal input is your current directory."))
- self.text.configure(state = "disabled")
- class GameWin:
- def __init__(self, master):
- self.master = master
- self.master.title("Hacker")
- self.main_frame = Frame(self.master, bd = 10, bg = uni_bg)
- self.main_frame.grid(sticky = "nsew")
- self.left_frame = Frame(self.main_frame, bd = 10, bg = uni_bg)
- self.left_frame.grid(column = 0, row = 0)
- self.right_frame = Frame(self.main_frame, bd = 10, bg = uni_bg)
- self.right_frame.grid(column = 1, row = 0)
- self.right_frame.columnconfigure(0, weight = 1)
- self.right_frame.rowconfigure(0, weight = 1)
- self.right_frame.columnconfigure(1, weight = 1)
- self.right_frame.rowconfigure(1, weight = 1)
- self.web = Text(self.left_frame, font = (uni_font, 12), wrap = WORD, bg = uni_bt_bg, fg = uni_fg)
- self.web.grid(column = 0, row = 0, padx = 5, pady = 5)
- self.output = Text(self.left_frame, font = (uni_font, 12), wrap = WORD, bg = "black", fg = uni_fg)
- self.output.grid(column = 0, row = 1, padx = 5, pady = 5, sticky = "ew")
- self.output.configure(state = "disabled")
- self.input = Entry(self.left_frame, font = (uni_font, 12))
- self.input.grid(column = 0, row = 2, sticky = "ew")
- self.input.bind('<Return>', self.submit)
- self.notepad = Text(self.right_frame, font = (uni_font, 12), wrap = WORD, bg = uni_fg, fg = "black")
- self.notepad.grid(column = 0, row = 0, pady = 5, rowspan = 2)
- self.sys_info = Text(self.right_frame, font = (uni_font, 12), wrap = WORD, bg = uni_bg, fg = uni_fg)
- self.sys_info.tag_configure('center', justify='center')
- self.sys_info.grid(column = 1, row = 0, pady = 5)
- self.sys_info.insert(END, "NAME", "center")
- self.sys_info.configure(state = "disabled")
- self.trace = Text(self.right_frame, font = (uni_font, 12), wrap = WORD, bg = uni_bg, fg = uni_fg)
- self.trace.grid(column = 1, row = 1, pady = 5)
- self.email = Text(self.right_frame, font = (uni_font, 12), wrap = WORD, bg = uni_bt_bg, fg = uni_fg)
- self.email.grid(column = 0, row = 2, pady = 5, columnspan = 2)
- self.email.configure(state = "disabled")
- self.respond = Entry(self.right_frame, font = (uni_font, 12))
- self.respond.grid(column = 0, row = 3, columnspan = 2, sticky = "ew")
- self.respond.bind('<Return>', self.do_respond)
- def submit(self, event):
- self.output.configure(state = "normal")
- self.output.configure(state = "disabled")
- pass
- def do_respond(self, event):
- pass
- root = Tk()
- mainwin = MainWin(root)
- root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement