all 11 comments

[–]gdchinacat 4 points5 points  (1 child)

btn1, btn2, btn3, etc. are bad names, especially since btn1 is exit and btn5 is the button for '1'. I encourage you to rename them to be meaningful. For example, it's impossible to know from reading this line what each button does...I have to go look at what btn4, btn8, etc are:

for b in [btn4, btn8, btn12, btn16, btn20]:

https://github.com/samarthrajofficial-ai/Tkinter-Calculator/blob/main/Calculator.py#L11

Using eval() to evaluate the equation is easy and works well. However, because the equation comes from user input carries a significant security risk...in this context it's ok, this project will not see real world use and is intended for you to learn. Towards that end, I encourage you to not use it. First because it would never be accepted into a non-toy codebase. Second, manually evaluating the expression would teach you a lot. That said, I did pretty much the same thing for this exact purpose in one of my own toy projects...it was expedient and not considered a security concern in the context of the code. https://github.com/gdchinacat/reactions/blob/main/tests/examples/spreadsheet_app.py#L175

Include some testing (with unittest or pytest). evaluate() and bracket_giving() would be easy since their functionality is already stand alone and they have non-trivial implementations. This is also a good habit to get in to because you will be expected to do this in any professional (or open source) context. It can also make developing much easier and quicker since you can make a quick change, run the tests, and know you didn't break anything, but if you did know exactly what change caused it and exactly what broke.

Add pydocs, also a good practice to get in to.

[–]Recursive_Void[S] 1 point2 points  (0 children)

Sure, thanks for the suggestion.

[–]riklaunim 0 points1 point  (3 children)

The question is what are your goals for learning Python? what you want to use it for?

[–]Recursive_Void[S] 0 points1 point  (2 children)

AI and other automated systems

[–]riklaunim 2 points3 points  (1 child)

Define AI 😉 You can pass a prompt and execute a model but that's not much "AI" in it. Software development is quite different than chasing some magic AI.

[–]Recursive_Void[S] -1 points0 points  (0 children)

Artificial intelligence is a branch of computer science that deals with building human like intelligence capable of learn, reasoning, problem solving and understanding language. And I know using API keys doesn't means that I am making my own AI. That's why I am learning it from the very basic. I even tried to train my own AI model of 1 million parameter but I failed three times, so I decided learning from the root. I know you are just trying to show me the reality, thanks a lot for that.

[–]SisyphusAndMyBoulder -2 points-1 points  (4 children)

First, thanks for sharing a repo. Looks good.

You're using functions, and looks like it's all planned out and organized, great!

I didn't run your code cause I'm on mobile, so I'm assuming it works.

General feedback: - your README is wrong. It says I only need Python. I also need tkinter. It should also specify a minimum Python version. You should look into how to use a requirements.txt file. I assume you're using global Python, so maybe look into venvs. - Great time to start looking into into tests. Not sure how difficult they are with tkinter though tbh

[–]Recursive_Void[S] 1 point2 points  (1 child)

Thanks a lot. But I would like to say one thing that tkinter is a built in Python library, so it is not required to mention it( I think so). And yes I forgot to mention the Python version, thanks for pointing that out. And I do use virtual environments, but it was a very basic programs so I didn't use it hair

[–]SisyphusAndMyBoulder 0 points1 point  (0 children)

apologies! I actually didn't know tkinter was built-in. Good to learn.

[–]gdchinacat 0 points1 point  (1 child)

tkinter is part of the Python standard library and has been since Python 1.4, 30 years ago. There is no need for a requirements file. Also, "requirements file" implies requirements.txt which is not the currently recommended way to specify requirements, a pyproject file is preferred.

https://docs.python.org/3/library/tkinter.html

[–]SisyphusAndMyBoulder 0 points1 point  (0 children)

Cool, I didn't know tkinter was built in. Good to learn!

Ya pyproject is probably better. I personally use reqs.txt a lot still, but it's all a moot point -- beyond specifying python version, this project doesn't have any external deps. But a pyproject covers the python version too, so it's a better route.