Python Forum
Python code review | Tkinter gui application
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Python code review | Tkinter gui application
#8
(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
Reply


Messages In This Thread
RE: Python code review | Tkinter gui application - by Sr999 - Nov-28-2023, 11:38 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  GUI application - code review Sr999 3 1,063 Jan-06-2024, 10:14 PM
Last Post: Sr999
  Code review of my rock paper scissors game Milan 0 2,214 May-25-2022, 06:59 AM
Last Post: Milan
  Review on (new) Python module: Function but Lazy Python jeertmans 3 2,636 Nov-01-2021, 06:57 PM
Last Post: ndc85430
  First time python user - Calculator code review Steamy 1 2,418 Jul-22-2020, 05:59 PM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020