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 import tkinter as tk
from tkinter import ttk from tkinter import ttk
from generic import sanitize, type_hosts_listed, type_hosts_organized from generic import sanitize, type_hosts_listed, type_hosts_organized
class App(tk.Tk): class App(tk.Tk):
@ -12,21 +11,32 @@ class App(tk.Tk):
container.pack(side="top", fill="both", expand=True) container.pack(side="top", fill="both", expand=True)
container.grid_rowconfigure(0, weight=1) 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.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): class InputFrame(tk.Frame):
def __init__(self, parent, controller): def __init__(self, parent, controller):
tk.Frame.__init__(self, parent) tk.Frame.__init__(self, parent)
self.controller = controller
label = tk.Label(self, text="Input URL, IP, email address") label = tk.Label(self, text="Input URL, IP, email address")
label.pack(padx=10, pady=10) label.pack(padx=10, pady=10)
self.var = tk.Variable()
self.entry = ttk.Entry(self) self.entry = ttk.Entry(self)
self.entry.focus() self.entry.focus()
@ -34,18 +44,33 @@ class InputFrame(tk.Frame):
self.entry.bind("<Return>", self.key_handler_function) self.entry.bind("<Return>", self.key_handler_function)
def key_handler_function(self, event) -> None: def key_handler_function(self, event) -> None:
inputs = self.entry.get() self.event = event
sanitized = sanitize.strip_and_list(inputs) self.inputs = self.entry.get()
typed = type_hosts_organized.type_hosts(sanitized) self.sanitized = sanitize.strip_and_list(self.inputs)
self.var.set(typed) self.typed = type_hosts_organized.type_hosts(self.sanitized)
print(self.controller.var.set(self.typed))
self.controller.lookup()
class LookupFrame(tk.Frame): class LookupFrame(tk.Frame):
def __init__(self, parent, controller): def __init__(self, parent, controller):
tk.Frame.__init__(self, parent) tk.Frame.__init__(self, parent)
self.controller = controller
self.var = controller.var.get()
label = tk.Label(self, text="Lookup information") label = tk.Label(self, text="Lookup information")
label.pack(padx=10, pady=10) 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__": if __name__ == "__main__":
testObj = App() testObj = App()

View File

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