Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding a Awesome GUI calculator. #1987

Merged
merged 7 commits into from
Oct 5, 2023

Conversation

NitkarshChourasia
Copy link
Contributor

  • Removed a documentation site I was working on, to teach python programming language, for now, removed it as I was still working on it.
  • Added an Awesome Tkinter made GUI based, calculator.

@NitkarshChourasia
Copy link
Contributor Author

@sarayusreeyadavpadala @OfficialAhmed
Please review them, guys.

@NitkarshChourasia
Copy link
Contributor Author

@sarayusreeyadavpadala @OfficialAhmed
Please review them.

Copy link
Contributor

@OfficialAhmed OfficialAhmed left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OOP is always recommended for GUI / more complex programs. It's easier to maintain and fix bugs using OOP implementation. On top of that, the global variables in Python considered bad practice especially if it's a big project containing multiple files and folders, it's prone to errors more often using globals in Python. Just wanted to share these notes they may be helpful in the next projects. But overall Great work you did good 👍🏻

@NitkarshChourasia
Copy link
Contributor Author

OOP is always recommended for GUI / more complex programs. It's easier to maintain and fix bugs using OOP implementation. On top of that, the global variables in Python considered bad practice especially if it's a big project containing multiple files and folders, it's prone to errors more often using globals in Python. Just wanted to share these notes they may be helpful in the next projects. But overall Great work you did good 👍🏻

@OfficialAhmed
As always, thanks and great reply.
Thank you.
Learning, as learning is a lifelong, process, your suggestions to improve do help me a lot.

@NitkarshChourasia
Copy link
Contributor Author

OOP is always recommended for GUI / more complex programs. It's easier to maintain and fix bugs using OOP implementation. On top of that, the global variables in Python considered bad practice especially if it's a big project containing multiple files and folders, it's prone to errors more often using globals in Python. Just wanted to share these notes they may be helpful in the next projects. But overall Great work you did good 👍🏻

@OfficialAhmed
You said so, but how to do otherwise.
Like if there are two functions. for example, below.

from tkinter import *
import hupper


def start_reloader():
    reloader = hupper.start_reloader("tkinter_1.main")


def close_app():
    root.destroy()


def main():
    root = Tk()
    root.title("Counting Seconds")

    button = Button(root, text="Stop", width=25, command=close_app)
    button.pack()

    root.mainloop()
    
    

@NitkarshChourasia
Copy link
Contributor Author

OOP is always recommended for GUI / more complex programs. It's easier to maintain and fix bugs using OOP implementation. On top of that, the global variables in Python considered bad practice especially if it's a big project containing multiple files and folders, it's prone to errors more often using globals in Python. Just wanted to share these notes they may be helpful in the next projects. But overall Great work you did good 👍🏻

@OfficialAhmed You said so, but how to do otherwise. Like if there are two functions. for example, below.

from tkinter import *
import hupper


def start_reloader():
    reloader = hupper.start_reloader("tkinter_1.main")


def close_app():
    root.destroy()


def main():
    root = Tk()
    root.title("Counting Seconds")

    button = Button(root, text="Stop", width=25, command=close_app)
    button.pack()

    root.mainloop()
    

@OfficialAhmed The only way to run them is declare root as global.

@OfficialAhmed
Copy link
Contributor

This is why OOP is easier in this case

  • We can store globals in one class and access them via objects or inheritance

  • Or write all the functions in one class as methods and the globals will be accessible through the self keyword using init

In your case only one global is set but as you add more features you'll realize adding more globals is the only way. thats where it starts to get complicated and difficult to handle bugs

@OfficialAhmed
Copy link
Contributor

"""python

class Environment:
ROOT_PATH = os.getcwd() + "\"
DATA_PATH = ROOT_PATH + "data\"
CACHE_FILE = DATA_PATH + "Cache.json"

 # STATIC OBJECTS - RECUSIVE ENABLED BY DEFAULT 
 FILE_FINDER = Finder.File 
 FOLDER_FINDER = Finder.Folder 

 def __init__(self) -> None: 
     self.file_finder = Finder.File() 
     self.folder_finder = Finder.Folder() 
     self.trash_folder_path = "trash\\" 

     self.trash_content_file = f"{self.trash_folder_path}content.json" 

 def update_param(self, path: str, is_recursive: bool) -> None: 
     self.file_finder.set_path(path) 
     self.file_finder.set_recursive(is_recursive) 

     self.folder_finder.set_path(path) 
     self.folder_finder.set_recursive(is_recursive) 

 def get_files_by_name(self, name: str) -> dict: 
     return self.file_finder.find("NAME", name) 

 def get_files_by_extension(self, extension: str) -> dict: 
     return self.file_finder.find("EXTENSION", extension) 

"""

You can see in this implementation I needed 4 variables to share between multiple functions without OOP the only way is through globals and this is few functions... more functions more globals

@NitkarshChourasia
Copy link
Contributor Author

@geekcomputers

@NitkarshChourasia
Copy link
Contributor Author

"""python

class Environment: ROOT_PATH = os.getcwd() + "" DATA_PATH = ROOT_PATH + "data" CACHE_FILE = DATA_PATH + "Cache.json"

 # STATIC OBJECTS - RECUSIVE ENABLED BY DEFAULT 
 FILE_FINDER = Finder.File 
 FOLDER_FINDER = Finder.Folder 

 def __init__(self) -> None: 
     self.file_finder = Finder.File() 
     self.folder_finder = Finder.Folder() 
     self.trash_folder_path = "trash\\" 

     self.trash_content_file = f"{self.trash_folder_path}content.json" 

 def update_param(self, path: str, is_recursive: bool) -> None: 
     self.file_finder.set_path(path) 
     self.file_finder.set_recursive(is_recursive) 

     self.folder_finder.set_path(path) 
     self.folder_finder.set_recursive(is_recursive) 

 def get_files_by_name(self, name: str) -> dict: 
     return self.file_finder.find("NAME", name) 

 def get_files_by_extension(self, extension: str) -> dict: 
     return self.file_finder.find("EXTENSION", extension) 

"""

You can see in this implementation I needed 4 variables to share between multiple functions without OOP the only way is through globals and this is few functions... more functions more globals

So using class is the way. Okay.

@geekcomputers geekcomputers merged commit 2d02c91 into geekcomputers:master Oct 5, 2023
1 check failed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants