62 lines
1.7 KiB
Python
62 lines
1.7 KiB
Python
|
# based on tkinter-oop-2.py
|
||
|
|
||
|
# Thinking in Frames: one Frame is the user input and its label, four more for the host type Listboxes, a last one for the host formatting?
|
||
|
|
||
|
import tkinter as tk
|
||
|
from tkinter import ttk
|
||
|
|
||
|
from generic import sanitize, type_hosts_listed
|
||
|
|
||
|
ENTRY_LABEL = "Enter some IPs, domains, email addresses:"
|
||
|
APP_TITLE = "Extract and look up hosts"
|
||
|
|
||
|
|
||
|
class InputFrame(ttk.Frame):
|
||
|
def __init__(self, container):
|
||
|
super().__init__(container)
|
||
|
self.columnconfigure(0, weight=1)
|
||
|
self.columnconfigure(1, weight=1)
|
||
|
self.columnconfigure(2, weight=1)
|
||
|
self.columnconfigure(3, weight=1)
|
||
|
|
||
|
self.__create_widgets()
|
||
|
|
||
|
def __create_widgets(self) -> None:
|
||
|
ttk.Label(self, text=ENTRY_LABEL).grid(column=0, row=0)
|
||
|
self.entry = ttk.Entry(self)
|
||
|
self.entry.focus()
|
||
|
self.entry.grid(column=0, row=1, columnspan=4, sticky="nsew")
|
||
|
self.entry.bind("<Return>", self.key_handler_function)
|
||
|
|
||
|
for widget in self.winfo_children():
|
||
|
widget.grid(padx=0, pady=5)
|
||
|
|
||
|
def key_handler_function(self, event) -> None:
|
||
|
inputs = self.entry.get()
|
||
|
sanitized = sanitize.strip_and_list(inputs)
|
||
|
typed = type_hosts_listed.type_hosts(sanitized)
|
||
|
|
||
|
|
||
|
class App(tk.Tk):
|
||
|
def __init__(self):
|
||
|
super().__init__()
|
||
|
self.title(APP_TITLE)
|
||
|
self.geometry("400x150")
|
||
|
self.resizable(None, None)
|
||
|
|
||
|
# layout on the root window
|
||
|
self.columnconfigure(0, weight=4)
|
||
|
self.columnconfigure(1, weight=1)
|
||
|
|
||
|
self.__create_widgets()
|
||
|
|
||
|
def __create_widgets(self) -> None:
|
||
|
# create the input frame
|
||
|
input_frame = InputFrame(self)
|
||
|
input_frame.grid(column=0, row=0)
|
||
|
|
||
|
|
||
|
if __name__ == "__main__":
|
||
|
app = App()
|
||
|
app.mainloop()
|