Advertisement
Guest User

Untitled

a guest
Sep 23rd, 2019
363
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 9.95 KB | None | 0 0
  1. from tkinter import *
  2. import tkinter.ttk as ttk
  3. from globals import *
  4. import random
  5. import pickle
  6. import locale
  7. locale.setlocale(locale.LC_ALL, 'en_US') #sets locale to US for number formatting
  8.  
  9. #universal background, text, button background, button text color
  10. uni_bg = "gray6"
  11. uni_fg = "gray90"
  12. uni_bt_bg = "gray35"
  13. uni_bt_fg = "black"
  14. uni_bt_active = "gray45"
  15. uni_font = "fixedsys"
  16. gamestate = GameState()
  17.  
  18. class MainWin():
  19.     def __init__(self, master):
  20.         self.master = master
  21.         self.master.title("Hacker")
  22.         self.master.geometry("770x520")
  23.         self.master.attributes("-fullscreen", True)
  24.         self.master.configure(background = uni_bg)
  25.         self.master.columnconfigure(0, weight = 1)
  26.         self.master.rowconfigure(0, weight = 1)
  27.         self.master.bind("<F11>", self.toggle_fullscreen)
  28.         self.master.bind("<Escape>", self.end_fullscreen)
  29.         w = self.master.winfo_screenwidth()
  30.         h = self.master.winfo_screenheight()
  31.  
  32.         try:
  33.             unpickle_users = open("users.pickle", "rb")
  34.             gamestate.user_dict = pickle.load(unpickle_users)
  35.         except:
  36.             pass
  37.        
  38.         self.main_frame = Frame(self.master, bd = 10, bg = uni_bg)
  39.         self.main_frame.grid()
  40.        
  41.         self.lbl = Label(self.main_frame, text = "Hacker", font = (uni_font, 36), bg = uni_bg, fg = uni_fg)
  42.         self.lbl.grid(column = 0, row = 0, pady = 10, sticky = "nsew")
  43.        
  44.         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)
  45.         self.login_bt.grid(column = 0, row = 1, padx = 5, pady = 5, sticky = "nsew")
  46.    
  47.         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)
  48.         self.register_bt.grid(column = 0, row = 2, padx = 5, pady = 5, sticky = "nsew")
  49.        
  50.         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)
  51.         self.tutorial_bt.grid(column = 0, row = 3, padx = 5, pady = 5, sticky = "nsew")
  52.        
  53.         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)
  54.         self.quit_bt.grid(column = 0, row = 4, padx = 5, pady = 5, sticky = "nsew")
  55.        
  56.     def tutorial(self):
  57.         self.main_frame.destroy()
  58.         TutorialWin(self.master)
  59.        
  60.     def quit(self):
  61.         root.destroy()
  62.        
  63.     def login(self):
  64.         self.main_frame.destroy()
  65.         LoginWin(self.master)
  66.    
  67.     def register(self):
  68.         self.main_frame.destroy()
  69.         RegisterWin(self.master)
  70.        
  71.     def toggle_fullscreen(self, event=None):
  72.         self.state = not self.state  # Just toggling the boolean
  73.         self.master.attributes("-fullscreen", self.state)
  74.         return "break"
  75.  
  76.     def end_fullscreen(self, event=None):
  77.         self.state = False
  78.         self.master.attributes("-fullscreen", False)
  79.         return "break"
  80.  
  81. class LoginWin:
  82.     def __init__(self, master):
  83.         self.master = master
  84.         self.master.title("Login")
  85.        
  86.         self.main_frame = Frame(self.master, bd = 10, bg = uni_bg)
  87.         self.main_frame.grid()
  88.        
  89.         self.lbl = Label(self.main_frame, text = "Hacker", font = (uni_font, 36), bg = uni_bg, fg = uni_fg)
  90.         self.lbl.grid(column = 0, row = 0, pady = 10, sticky = "nsew")
  91.        
  92.         self.status = Label(self.main_frame, text = " ", font = (uni_font, 12), bg = uni_bg, fg = uni_fg)
  93.         self.status.grid(row = 5, pady = 10, sticky = "nsew")
  94.        
  95.         self.name_entry = Entry(self.main_frame, font = (uni_font, 12))
  96.         self.name_entry.insert(END, "Username")
  97.         self.name_entry.grid(row = 1, sticky = "nsew", pady = 10)
  98.         self.pass_entry = Entry(self.main_frame, font = (uni_font, 12))
  99.         self.pass_entry.insert(END, "Password")
  100.         self.pass_entry.grid(row = 2, sticky = "nsew")
  101.  
  102.         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)
  103.         self.enter_bt.grid(row = 3, sticky = "nsew", pady = 10)
  104.        
  105.         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)
  106.         self.back_bt.grid(row = 4, sticky = "nsew")
  107.        
  108.     def submit(self):
  109.         possible_user = self.name_entry.get()
  110.         possible_password = self.pass_entry.get()
  111.         if possible_user in gamestate.user_dict and possible_password == gamestate.user_dict[possible_user]:
  112.             unpickle_user = open(possible_user + "save.pickle", "rb")
  113.             savestate = pickle.load(unpickle_user)
  114.             unpickle_user.close()
  115.             self.main_frame.destroy()
  116.             GameWin(self.master)
  117.         else:
  118.             self.status.configure(text = "Incorrect credentials")
  119.        
  120.     def back(self):
  121.         self.main_frame.destroy()
  122.         MainWin(self.master)
  123.        
  124. class RegisterWin:
  125.     def __init__(self, master):
  126.         self.master = master
  127.         self.master.title("Register")
  128.        
  129.         self.main_frame = Frame(self.master, bd = 10, bg = uni_bg)
  130.         self.main_frame.grid()
  131.        
  132.         self.lbl = Label(self.main_frame, text = "Hacker", font = (uni_font, 36), bg = uni_bg, fg = uni_fg)
  133.         self.lbl.grid(column = 0, row = 0, pady = 10, sticky = "nsew")
  134.        
  135.         self.status = Label(self.main_frame, text = " ", font = (uni_font, 12), bg = uni_bg, fg = uni_fg)
  136.         self.status.grid(row = 5, pady = 10, sticky = "nsew")
  137.        
  138.         self.name_entry = Entry(self.main_frame, font = (uni_font, 12))
  139.         self.name_entry.insert(END, "Username")
  140.         self.name_entry.grid(row = 1, sticky = "nsew", pady = 10)
  141.         self.pass_entry = Entry(self.main_frame, font = (uni_font, 12))
  142.         self.pass_entry.insert(END, "Password")
  143.         self.pass_entry.grid(row = 2, sticky = "nsew")
  144.  
  145.         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)
  146.         self.enter_bt.grid(row = 3, sticky = "nsew", pady = 10)
  147.        
  148.         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)
  149.         self.back_bt.grid(row = 4, sticky = "nsew")
  150.        
  151.     def submit(self):
  152.         possible_user = self.name_entry.get()
  153.         possible_password = self.pass_entry.get()
  154.         if possible_user in gamestate.user_dict and possible_password == gamestate.user_dict[possible_user]:
  155.             self.status.configure(text = "Username already exists!")
  156.         else:
  157.             gamestate.user_dict[possible_user] = possible_password
  158.             self.status.configure(text = "Registration successful!")
  159.             pickling_user_data = open(possible_user + "save.pickle","wb")
  160.             pickle.dump(gamestate, pickling_user_data)
  161.             pickling_user_data.close()
  162.            
  163.             pickling_users = open("users.pickle", "wb")                                                                     # saving list of all users
  164.             pickle.dump(gamestate.user_dict, pickling_users)
  165.             pickling_users.close()
  166.        
  167.     def back(self):
  168.         self.main_frame.destroy()
  169.         MainWin(self.master)
  170.        
  171. class TutorialWin:
  172.     def __init__(self, master):
  173.         self.master = master
  174.         self.master.title("Tutorial")
  175.        
  176.         self.main_frame = Frame(self.master, bd = 10, bg = uni_bg)
  177.         self.main_frame.grid()
  178.        
  179.         self.text = Text(self.main_frame, font = (uni_font, 12), wrap = WORD, bg = uni_bg, fg = uni_fg, highlightbackground = uni_fg, highlightthickness = 3)
  180.         self.text.grid(row = 0)
  181.         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" \
  182.                 "\nThe prompt in the bottom left of the terminal input is your current directory."))
  183.         self.text.configure(state = "disabled")
  184.        
  185. class GameWin:
  186.     def __init__(self, master):
  187.         self.master = master
  188.         self.master.title("Hacker")
  189.        
  190.         self.main_frame = Frame(self.master, bd = 10, bg = uni_bg)
  191.         self.main_frame.grid(sticky = "nsew")
  192.        
  193.         self.left_frame = Frame(self.main_frame, bd = 10, bg = uni_bg)
  194.         self.left_frame.grid(column = 0, row = 0)
  195.        
  196.         self.right_frame = Frame(self.main_frame, bd = 10, bg = uni_bg)
  197.         self.right_frame.grid(column = 1, row = 0)
  198.        
  199.         self.right_frame.columnconfigure(0, weight = 1)
  200.         self.right_frame.rowconfigure(0, weight = 1)
  201.         self.right_frame.columnconfigure(1, weight = 1)
  202.         self.right_frame.rowconfigure(1, weight = 1)
  203.        
  204.         self.web = Text(self.left_frame, font = (uni_font, 12), wrap = WORD, bg = uni_bt_bg, fg = uni_fg)
  205.         self.web.grid(column = 0, row = 0, padx = 5, pady = 5)
  206.        
  207.         self.output = Text(self.left_frame, font = (uni_font, 12), wrap = WORD, bg = "black", fg = uni_fg)
  208.         self.output.grid(column = 0, row = 1, padx = 5, pady = 5, sticky = "ew")
  209.         self.output.configure(state = "disabled")
  210.        
  211.         self.input = Entry(self.left_frame, font = (uni_font, 12))
  212.         self.input.grid(column = 0, row = 2, sticky = "ew")
  213.         self.input.bind('<Return>', self.submit)
  214.        
  215.         self.notepad = Text(self.right_frame, font = (uni_font, 12), wrap = WORD, bg = uni_fg, fg = "black")
  216.         self.notepad.grid(column = 0, row = 0, pady = 5, rowspan = 2)
  217.        
  218.         self.sys_info = Text(self.right_frame, font = (uni_font, 12), wrap = WORD, bg = uni_bg, fg = uni_fg)
  219.         self.sys_info.tag_configure('center', justify='center')
  220.         self.sys_info.grid(column = 1, row = 0, pady = 5)
  221.         self.sys_info.insert(END, "NAME", "center")
  222.         self.sys_info.configure(state = "disabled")
  223.        
  224.         self.trace = Text(self.right_frame, font = (uni_font, 12), wrap = WORD, bg = uni_bg, fg = uni_fg)
  225.         self.trace.grid(column = 1, row = 1, pady = 5)
  226.        
  227.         self.email = Text(self.right_frame, font = (uni_font, 12), wrap = WORD, bg = uni_bt_bg, fg = uni_fg)
  228.         self.email.grid(column = 0, row = 2, pady = 5, columnspan = 2)
  229.         self.email.configure(state = "disabled")
  230.        
  231.         self.respond = Entry(self.right_frame, font = (uni_font, 12))
  232.         self.respond.grid(column = 0, row = 3, columnspan = 2, sticky = "ew")
  233.         self.respond.bind('<Return>', self.do_respond)
  234.        
  235.     def submit(self, event):
  236.         self.output.configure(state = "normal")
  237.         self.output.configure(state = "disabled")
  238.         pass
  239.    
  240.     def do_respond(self, event):
  241.         pass
  242.  
  243. root = Tk()
  244. mainwin = MainWin(root)
  245. root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement