Nov-28-2023, 11:38 PM
(Nov-28-2023, 11:14 PM)menator01 Wrote: I was intrigued by your project and started to take my own approach from your project. This will give you an example of how I was taught or advised how to do imports. I've only done the cover part. Buttons don't work yet.
import tkinter as tk import pandas as pd from datetime import date from random import sample import math import os # Create path to executing directory path = os.path.realpath(os.path.dirname(__file__)) class Data: ''' Class will handle all data manipulations ''' def __init__(self): pass class Window: ''' Class will handle all views ''' def __init__(self, parent): parent.columnconfigure(0, weight=1) parent.rowconfigure(0, weight=1) parent.minsize(800,600) parent.resizable(False, False) container = tk.Frame(parent) container.grid(column=0, row=0, sticky='news') container.columnconfigure(0, weight=3) logo = tk.PhotoImage(file=f'{path}/resources/PasswordManager/logo.png') logo.backup = logo header = tk.Label(container) header['image'] = logo header.grid(column=0, row=0, padx=5, pady=0, sticky='new') btn_frame = tk.Frame(container) btn_frame.grid(column=0, row=1, sticky='new', padx=800/3, pady=5) btn_frame.grid_columnconfigure(0, weight=3, uniform='btn') btn_frame.grid_columnconfigure(1, weight=3, uniform='btn') self.display_btn = tk.Button(btn_frame, text='Display', cursor='hand2') self.display_btn['bg'] = 'red' self.display_btn['fg'] = 'white' self.display_btn.grid(column=0, row=0, sticky='new', padx=2, pady=2) self.display_btn.bind('<Enter>', lambda event: self.hover(self.display_btn)) self.add_btn = tk.Button(btn_frame, text='Add', cursor='hand2') self.add_btn['bg'] = 'red' self.add_btn['fg'] = 'white' self.add_btn.grid(column=1, row=0, sticky='new', padx=4, pady=4) self.add_btn.bind('<Enter>', lambda event: self.hover(self.add_btn)) def hover(self, btn): btn['activebackground'] = 'white' btn['activeforeground'] = 'red' class Controller: def __init__(self, data, window): ''' Class will handle communications between Data and Window classes ''' self.data = data self.window = window # Button Commands self.window.display_btn['command'] = self.display self.window.add_btn['command'] = self.add def display(self): print('display here') def add(self): print('Add data') if __name__ == '__main__': root = tk.Tk() controller = Controller(Data(), Window(root)) root.mainloop()
Hey again, your code actually look much better and professional and I see there is good use of OOP here and I didnt even think about using it , I am waiting to see the full code you will right as I see I have a lot to learn