finally got the execution flow right. The root app instantiates and gridss the input and look up frame => the input frame waits for input => the root app displays the data put in. I probably can still subclass the root app lookup() function, I just need to follow this execution flow. Happy! :D

This commit is contained in:
Joost Agterhoek 2024-08-23 21:37:53 +02:00
parent 2dcb189902
commit 9002f0b11f
2 changed files with 40 additions and 14 deletions

View File

@ -1,6 +1,5 @@
import tkinter as tk
from tkinter import ttk
from generic import sanitize, type_hosts_listed, type_hosts_organized
class App(tk.Tk):
@ -12,21 +11,32 @@ class App(tk.Tk):
container.pack(side="top", fill="both", expand=True)
container.grid_rowconfigure(0, weight=1)
container.grid_columnconfigure(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())
# I think this goes wrong for my purposes: I'm not switching frames in place, but keeping them besides each other. Find a simpler setup maybe?
self.frames = {}
for F in (InputFrame, LookupFrame):
frame = F(container, self)
frame.grid(row=0, column=0, sticky='nsew')
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.var = tk.Variable()
self.entry = ttk.Entry(self)
self.entry.focus()
@ -34,18 +44,33 @@ class InputFrame(tk.Frame):
self.entry.bind("<Return>", self.key_handler_function)
def key_handler_function(self, event) -> None:
inputs = self.entry.get()
sanitized = sanitize.strip_and_list(inputs)
typed = type_hosts_organized.type_hosts(sanitized)
self.var.set(typed)
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)
var = controller.var.get()
print(var)
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()

View File

@ -79,6 +79,7 @@ url_listbox = tk.Listbox(root)
email_label = tk.Label(root, text="email address => DMARC/SPF")
email_listbox = tk.Listbox(root)
var = tk.Variable()
print(var)
entrylabel.grid(column=1, row=0, columnspan=2, sticky="nsew")
entry.grid(column=0, row=1, columnspan=4, sticky="nsew")
ip_label.grid(column=0, row=2, columnspan=2, sticky="nsew")