Just wanted to post what I came up with. Maybe it will help someone in the future.
#! /usr/bin/env python3.8 '''Docstring''' ###### Do the imports ###### import tkinter as tk from tkinter import ttk, messagebox import string from functools import partial from PIL import Image, ImageTk from modules import database as db ###### Intiate the window ###### class RootWindow: '''Docstring''' def __init__(self, master): self.master = master self.master.columnconfigure(0, weight=1) self.master.rowconfigure(0, weight=1) ###### Intiate all of our main containerframes ###### self.logo_frame() self.letter_frame() self.container_frame() self.title_frame() self.recipe_frame() self.footer_frame() ###### Initate the widgets ###### Child(self.logoframe, self.footerframe) Child2().lettermenu(self.letterframe, self.containerframe) Child3().titlemenu(self.containerframe) ###### This sets all the container frames ###### ###### Need to create a class for generic ###### ###### frames to eliminate repetitive code ##### def logo_frame(self): '''logo frame''' self.logoframe = ttk.Frame(self.master, border=5, relief='ridge') self.logoframe.grid(column=0, row=0, sticky='new') self.logoframe.grid_columnconfigure(0, weight=3) def letter_frame(self): '''letterframe''' self.letterframe = ttk.Frame(self.master, border=5, relief='ridge') self.letterframe.grid(column=0, row=1, sticky='new') for i in range(26): self.letterframe.grid_columnconfigure(i, weight=3) def container_frame(self): '''Container frame will hold two frames. Title frame and recipe frame''' self.containerframe = ttk.Frame(self.master) self.containerframe.grid(column=0, row=2, sticky='nw') self.containerframe.grid_columnconfigure(0, weight=3) def title_frame(self): '''Title Frame''' self.titleframe = ttk.Frame(self.containerframe, border=5, relief='ridge') self.titleframe.grid(column=0, row=0, sticky='nw') self.titleframe.grid_columnconfigure(0, weight=3) def recipe_frame(self): '''Recipe Frame''' self.recipeframe = ttk.Frame(self.containerframe, border=5, relief='ridge') self.recipeframe.grid(column=1, row=1) self.recipeframe.grid_columnconfigure(0, weight=3) def footer_frame(self): '''footer''' self.footerframe = ttk.Frame(self.master, border=5, relief='ridge') self.footerframe.grid(column=0, row=3, sticky='new') self.footerframe.grid_columnconfigure(0, weight=3) ###### This class defines and displays header and footer ###### class Child: '''logo''' def __init__(self, logoframe, footerframe): self.my_logo(logoframe) self.my_footer(footerframe) def my_logo(self, logoframe): '''doc''' load = Image.open('/home/johnny/Desktop/CookBook/images/cookbook_logo.png') render = ImageTk.PhotoImage(load) self.logo = ttk.Label(logoframe, image=render) self.logo.image = render self.logo.grid(column=0, row=0) def my_footer(self, footerframe): '''footer''' style = ttk.Style() style.map('Footer.TLabel', \ foreground=[('pressed', 'firebrick'), ('active', 'red')], \ background=[('pressed', '!disabled', 'gray86'), ('active', 'gray86')] \ ) style.configure('Footer.TLabel', foreground='blue', \ font=('Times', 12, 'normal', 'underline')) self.footer = ttk.Button(footerframe, text='My Footer', \ style='Footer.TLabel', cursor='hand2') self.footer.grid(column=0, row=0, ipady=3) ###### Class produces the letter menu ###### class Child2: '''doc''' def __init__(self): pass def lettermenu(self, letterframe, containerframe): '''lettermenu''' letters = string.ascii_uppercase i = 0 style = ttk.Style() style.configure('Btn.TButton', width=4) for letter in letters: button = ttk.Button(letterframe, text=letter, style='Btn.TButton', \ command=partial(Child3().titlemenu, containerframe, letter=letter)) button.grid(column=i, row=0, sticky='new') i += 1 ###### This class retrieves and displays recipe titles ###### class Child3: '''doc''' def __init__(self): pass def titlemenu(self, containerframe, letter='a'): '''title menu''' ###### Query the database for recipe titles from our letter menu defaults to a ###### data = db.Database().title_query(letter=letter) ###### Create the canvas and scrollbar ###### canvas = tk.Canvas(containerframe) scrollbar = ttk.Scrollbar(containerframe, orient='vertical', command=canvas.yview) scrollable_frame = ttk.Frame(canvas) scrollable_frame.bind( '<Configure>', lambda e: canvas.configure(scrollregion=canvas.bbox('all')) ) canvas.create_window((0, 0), window=scrollable_frame, anchor='nw') canvas.configure(yscrollcommand=scrollbar.set) ###### If there are not any results returned, display message ###### if not data: msg = messagebox.showerror(title='No listing', \ message='Sorry, there have not been any recipes added starting with ' + letter) if msg == 'ok': return True else: ###### Setup our look for the recipe menu ###### style = ttk.Style() style.map('L.TLabel', \ background=[('pressed', '!disabled', 'gray86'), ('active', '#ffffee')], \ foreground=[('pressed', 'red'), ('active', 'red')]) style.configure('L.TLabel', relief='flat', padding=2, foreground='blue') ###### Loop through and display the return results from the database ###### for recipe_id, title in data: title = ttk.Button(scrollable_frame, text=title.title(), \ style='L.TLabel', cursor='hand2') title.grid(column=0, row=recipe_id, sticky='nw') scrollbar.grid(column=0, row=0, sticky='nsw') canvas.grid(column=1, row=0, sticky='nsw') def main(): '''Docstring''' root = tk.Tk() RootWindow(root) root.mainloop() if __name__ == '__main__': main()
I welcome all feedback.
The only dumb question, is one that doesn't get asked.
My Github
How to post code using bbtags
The only dumb question, is one that doesn't get asked.
My Github
How to post code using bbtags