Hey everyone! I've been practicing Python for a bit and decided to try my hand at a basic calculator as my first project outside of tutorials. I'm trying to focus on getting better at object-oriented programming, but I'm not sure if my code is any good (it's probably not!). I'd really appreciate it if someone could take a look at my code and provide feedback, especially regarding the structure and any suggestions for improving my use of OOP. I'm open to any comments you might have! You can check out my project on GitHub: https://github.com/ilikkako/gtk4-python-calculator
4 Answers
You could give AI tools like Claude a try for code reviews, but I totally understand wanting human input. I find that real feedback from experienced programmers can be way more reliable than AI-generated advice.
First off, definitely avoid using bare 'except' statements or 'except Exception.' Always specify the exception you expect!
As for your code, consider adopting a match/case statement on lines 73 and 82 for better readability and future expansion. From a clean code perspective, using helper functions in your `on_button_clicked` method could make things clearer.
Also, type hints would be beneficial, especially since you reuse the 'app' variable with different types. Lastly, to improve reusability, it's common practice to put executed code under `if __name__ == '__main__':` to prevent it from running when the module is imported elsewhere.
I noticed a few things:
1. You might not need the constructor on line 23 unless you're planning to expand your functionality.
2. Consider making 'screen' and 'light_mode' members of the MainWindow class to eliminate globals; globals can lead to messy code.
3. Using `eval` is risky; it's better to avoid it whenever possible.
4. Instead of print statements on line 37, try using logging — it's a simple habit that pays off.
5. If you plan to expand this project, think about breaking out logic, formatting, etc., from the MainWindow class; keeping everything in one spot goes against good design principles.
Also, consider using `isdigit` instead of constants and try to combine the conditions on lines 73 and 75 for efficiency!

Related Questions
How To: Running Codex CLI on Windows with Azure OpenAI
Set Wordpress Featured Image Using Javascript
How To Fix PHP Random Being The Same
Why no WebP Support with Wordpress
Replace Wordpress Cron With Linux Cron
Customize Yoast Canonical URL Programmatically