gui-host-lookup/tkinter-enter-classed-2.py

80 lines
2.3 KiB
Python
Raw Permalink Normal View History

import tkinter as tk
from tkinter import ttk
from generic import sanitize, type_hosts_listed, type_hosts_organized
class App(tk.Tk):
def __init__(self, *args, **kwargs):
tk.Tk.__init__(self, *args, **kwargs)
self.wm_title("Testing out classing my application")
container = tk.Frame(self, height=400, width=600)
container.pack(side="top", fill="both", expand=True)
container.grid_rowconfigure(0, weight=1)
container.grid_rowconfigure(1, weight=1)
container.grid_columnconfigure(1, weight=1)
container.grid_columnconfigure(2, weight=1)
container.grid_columnconfigure(3, weight=1)
self.var = tk.Variable()
self.blahblah = 315
input_frame = InputFrame(container, self)
input_frame.grid(row=0, column=0, sticky='nsew')
lookup_frame = LookupFrame(container, self)
lookup_frame.grid(row=1, column=0, sticky='nsew')
# self.lookup()
def lookup(self):
print("FROM THE APP CLASS")
print(self.var.get())
class InputFrame(tk.Frame):
def __init__(self, parent, controller):
tk.Frame.__init__(self, parent)
self.controller = controller
label = tk.Label(self, text="Input URL, IP, email address")
label.pack(padx=10, pady=10)
self.entry = ttk.Entry(self)
self.entry.focus()
self.entry.pack(padx=10, pady=10)
self.entry.bind("<Return>", self.key_handler_function)
def key_handler_function(self, event) -> None:
self.event = event
self.inputs = self.entry.get()
self.sanitized = sanitize.strip_and_list(self.inputs)
self.typed = type_hosts_organized.type_hosts(self.sanitized)
print(self.controller.var.set(self.typed))
self.controller.lookup()
class LookupFrame(tk.Frame):
def __init__(self, parent, controller):
tk.Frame.__init__(self, parent)
self.controller = controller
self.var = controller.var.get()
label = tk.Label(self, text="Lookup information")
label.pack(padx=10, pady=10)
self.ip_listbox = tk.Listbox(self)
self.ip_listbox.pack(padx=10, pady=10)
def lookup(self):
whatever = self.controller.var.get()
print(whatever)
if __name__ == "__main__":
testObj = App()
testObj.mainloop()