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 new project - Calculate Weights in different planets using tkinter #226

Merged
merged 1 commit into from
Jun 2, 2024

Conversation

Astrasv
Copy link
Contributor

@Astrasv Astrasv commented Feb 18, 2024

Description

This is a simple Python mini-project created using Tkinter to calculate weight on different planets in our solar system.

Copy link
Contributor

@coderwessel coderwessel left a comment

Choose a reason for hiding this comment

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

I have reviewed the code and it looks good to be added to the repo.

Just for reference I have some suggestions for future improvement:

I advise to not use import * but use import as tk instead (see https://www.educative.io/answers/how-to-import-tkinter-in-python)

I advise to get rid of code repetition by using dictionary to store the relative weights of each planet like this:
rel_weight={"merc":3.7,"ven":8.87, etc,etc}

and use
one function for the weight calculation, and calling it with a planet parameter (myclickmerc then becomes planetclick(merc))
planetclick(planet):
weight_planet= round((int(e.get()) / 9.798) * rel_weight[planet], 2)
...

you can call functions with variables using a lambda function e.g.:
mybutton1= Button(root,text="Mercury", ..., command=myclickmerc, ...)
becomes:
mybutton1= Button(root,text="Mercury", ..., command= lambda: planetclick(merc), ...)

@ndleah ndleah merged commit fd0c788 into ndleah:main Jun 2, 2024
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.

None yet

3 participants