Simple GUI Calculator in Python
HTML-код
- Опубликовано: 14 ноя 2024
- Today we build a simple GUI calculator in Python. For the graphical user interface we use tkinter.
◾◾◾◾◾◾◾◾◾◾◾◾◾◾◾◾◾
📚 Programming Books & Merch 📚
🐍 The Python Bible Book: www.neuralnine...
💻 The Algorithm Bible Book: www.neuralnine...
👕 Programming Merch: www.neuralnine...
🌐 Social Media & Contact 🌐
📱 Website: www.neuralnine...
📷 Instagram: / neuralnine
🐦 Twitter: / neuralnine
🤵 LinkedIn: / neuralnine
📁 GitHub: github.com/Neu...
🎙 Discord: / discord
🎵 Outro Music From: www.bensound.com/
Literally explained better than half of the programmers in RUclips. Makes sense, explains, doesn't do unnecessary stuff.
this was super helpful and really well done! I actually really liked that you had the lambda still in there for the btn_equals...it let us see your debugging process. Thank you!
Yes
NeuralNine: *Making Calculator and is doing calculations on it*
Also NeuralNine: Am gonna do the calculations myself. Who needs a calculator?
19:46 Its the lambda bro!!
Thank you for this!
Stay on the upload grind!
one video every other day! 💪🏻
Try 4 videos Every day, It's a great schedule 😎@@NeuralNine
i really like that thats the first youtube project thats works without error, thank you sir
now i can not agree it dosent wor to me
Very simple and very useful!
Thanks for one more project like this!
Thanks for the tutorial! I have that kind of school project where I have to make a representation of your favorite hobby or that stuff! I planned to make it about coding and I'm trying to do 3 softwares for it and this is fricking good idea!
Already made that but still learnt something new❤️❤️❤️
nice flex
This is what i was looking for. Thanks to tutor.
super helpful and clear, thanks a lot
Why not make a class with attributes for the number, row and column, then make a function for creating the button and run it in a for loop.
This is how I did it, to save time and not repeat code.
I couldn't figure out how to make the loop also name the buttons incrementally (i.e. btn_1, then btn_2) so I had to type that manually.
Also had to manually type out the code for equals and clear as the command was different to the others.
Would love your thoughts.
Love your coding bro... Stay going on..
i have also a function if you want to remove one character from the calculation if you made an error typing, but you need an extra delete button for it:
def remove():
global calculation
if calculation:
calculation = calculation[:-1]
text_result.delete(1.0, "end")
text_result.insert(1.0, calculation)
pass
pass
Thank you so much.
thank buddy 🙏
Can you please explain why he .delete came before the .insert?
@@Veestar4u because of the grid placement you need to change it
I've always wanted to learn to program and this video helped me understand that my biggest enemy is going to be my dyslexia xD
love these projects!
the amount of time he takes to build the calculator is so impressive
Very much helpful to the python learners
I appreciate you, this is absolutely useful, nice tutorial
bro thank you very much. you made my day. keep up
Very simple and very useful!
Thanks ❤ 🇲🇦
man i love you, best is what i think you are!!!!
Loved it!!
very simle and helpful a lot, thank you a lot
Very nice video! More of this! :D
Really good tutorial, has helped improve my Python knowledge 😊
Thank you for the videos I like to scan them quick when i'm stuck
I really enjoyed this. Thank you very much.
Very nice tutorial. I very well understood. Really appreciate it 👏
I made the project the completely but I didn't learned many things from it because it was copy paste time type program for me .
which code editor did you use? I used codesandbox and don't show the pop up page for blank page for...
import tkinter as tk
calculation = ""
def add_to_calculation(symbol):
pass
def evaluate_calculation():
pass
def clear_field():
pass
root = tk.Tk()
root.geometry("300x275")
root.mainloop()
and shows up
Traceback (most recent call last):
File "calculator.py", line 18, in
root = tk.Tk()
File "/usr/local/lib/python3.8/tkinter/__init__.py", line 2270, in __init__
self.tk = _tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk, sync, use)
_tkinter.TclError: no display name and no $DISPLAY environment variable
@@Soo-qd1co I used pycharm for python development
You have made me switch from C# to python my friend
Thank you dude, I´m learning Python and this was perfect to achieve new knowledge
Greetins from Argentina
Nice. Do you think I can include this in my portfolio to apply for a job? I can say that I followed your tutorial and learned from it.
How does this do the actual math portion without telling it to do a math calculation? The other calculator I made doesn't have a GUI but all the code is to specify the actual math method being used versus, all we (you) did was create buttons. I followed along and just don't understand how it's automatically doing the math.
I think it's the eval() function that's doing the math. At 5:30 he mentions that the eval function will evaluate both mathematical equations as well as code.
the best tutorial ever bro u da best
The tutorial was topnotch
Big thanks man. Really appreciate what you do.
Awesome! 10 points
Thank you for the video!
If I want to make it so that I don't have to type a '*' before the parenthesis for the code to recognize that it should multiply, how do I make it so that this code recognizes that 'x(a)", where x and a are any number , are suppose to multiply? Like if I want it to calculate "90/3(1+2)"
i was wondering that too so i asked chatgpt and this is what it said:
To make the code recognize this implicit multiplication, you can add a check in the add_to_calculation function to see if the last symbol in the calculation string is a number, and if so, add the multiplication symbol before adding the parentheses.
Here is an updated add_to_calculation function that implements this logic:
def add_to_calculation(symbol):
global calculation
if symbol == "(" and calculation != "" and calculation[-1].isdigit():
calculation += "*"
calculation += str(symbol)
text_result.delete(1.0, "end")
text_result.insert(1.0, calculation)
With this code, if the user types a number followed by an opening parenthesis, the function will automatically insert a multiplication symbol before the parenthesis. This means that if the user types "90/3(1+2)", the calculation string will become "90/3*(1+2)" before evaluation.
@@jeez8136
So I was wondering this as well and have finally made it work behind the scenes without it showing it add the * before the (. Here is the code:
implicit = list(calculation)
i = 0
while i
thank you so much it works@@TheRealStrider
thanks for another very nice video😇😉
i would love if u explained what are you doing in ur actions
I love the project it was very useful and helpful thanks
Very simple Thank yous
nice vid liked n subed , made me feelike programming more
Interesting explanation ❤
Great bro i was finding this only from a long time.Thanks for uploading in this Content.I'm excited for your next video please upload it as soon as possible :) :) :) :) ;) ;)
Really really really Great i wish you more success ❤❤❤
Interesting explanation on the eval() functionality. But what alternatives would you suggest for better security?
I didn't watched it with audio on, so I don't know what security issues he mentioned, but I was wondering the whole video when would he write the regex code to interpret the string arithmetic expression.
It'd require some extra functions to substitute the eval() built-in.
For personal challenge, we could try to code these said extra functions.
I am noob, but I would not allowed letters, only go execute eval if there are no letters and other not allowed symbols
You need to implement a tree
What interface are you using? Looks very good. The standard IDE isn't as nice as this
PyCharm its really good
Thank you i found it and installed it right onto linux. It's a very nice interface and handy.
i learned a lot from this video and i did it myself as well
So wonderful
i learn from your video, thanks you soo much
brilliant! just one thing. i don't get the part where you put (1.0, "end") after text_result.delete or text_result.insert. what do they mean?
even i want to know the meaning of those parameters
In tkinter (for text), delete(first index position, last index position). The 1 is first line. The 0 is before first character. The "end" is to the end of the text. insert(index position, string)
@@timmyt1232 Would you mind explaining where this 'end' argument is defined? Tried to look into the source via PyCharm, but couldn't find where this is specified, not even in any documentation that I looked trough. How can I know what other strings are valid for the index parameter?
Can someone explain why he uses the .delete first before the .insert? What does that do?
Thank you sir ❤
this helped me so mauch thax
Thank you man🌻
You're the best one to explain, ty so much man
Thanks bro 🧑💻🧑💻
my kind of tutorial
so usefull and hepfull I subsribed this is my 2nd videio watching
do you need pycharm for this, or can you use the normal python application?
hi gojo kun
@@reaction_124 Nah i'd win.
How can i add √ and on off button could you please help me.
everything worked but the buttons only work individually instead of 1+2 it would just say the number by itself when clicked instead of holding memory. any tips or advice
Can anyone explain to me how he navigates the code by highlighting a single character then just skimming it? I'm a bit new to coding and am still learning much. - Thanks!
For the buttons why not just use a definition?
Thank you for sharing, I wonder how I can implement an %-Button with the correct function. I tried it but I can`t figure it out.
How do you do the copy paste trick??? damn. It seems like it's a shortcut key or somethin' it was so quick ahahahhah
Learning python on a calculator
Thats a classic chad move
Now that I can make custom buttons I can finally create the Calculator 2
SyntaxError: expected 'except' or 'finally' block
hi good video all in all but the code keeps on throwing the error message at me when i perform any calculations
Thanks!
thank you very much
Can you implement it with constants e and π , and also trigonometric functions
well do try to do it yourself
@@flowman8414 import math has trigonometric functions and also the inverse functions of themselves ?
@@mariustrelea5132 yea i think so
20:24, do equals without the lambda
Good stuff
Not working now it says TypeError: 'float' object is not subscriptable whenever i press a button
thanks bro❤
Fantastic
i like your video but why not to paste the code in the description
After lambda add to command is not showing in blue colour
i have tried installing this Tkinter but still wouldnt work on my window 10 or my mac pro. its so confusing i get this error : "ModuleNotFoundError: No module named '_tkinter'" what do i do
when you put root = tk.Tk() it worked perfectly for you but for me it's says AttributeError: module 'tkinter' has no attribute 'tk'
did u import tkinter as tk? otherwise u would have to write tkinter.Tk(), u should import it as tk not to waste time
Great tutorial!
But in my case (I don't know why) I have to use lambda for all functions so that it would work. And also the result of the previous calculation isn't transferred to the new one. Does anybody know what's wrong?
idk
show ur code
is it possible to make a delete button? If so how do you do it, cos i have been trying to figure it out for the past week, but still can’t (i’m a beginner btw)
can you help me?
I get the error:
ModuleNotFoundError: No module named 'tkinter'
when i tri to do the first test run. I cant seem to get it to work on any ide expect on python terminal alone.
import tkinter
The delete function is not working... Gives an Attribute error
Thanks a lot 🙏
could anyone explain more about the text_result.delete(1.0, "error") and text_result.insert(1.0, calculation). I'm confused as hell
How can I add percentage button in this program
thank you so much 😭😭😭😭🙏🙏🙏🙏
0:42 when he said nonsense haha
Where is the code , i wanna compare with mine pls
How to delete one number?
Brow what will I do if on calculator I click 1 and the result is always calculation
Thanks
thnx man
🙏
he looks like Nacho from Better call Saul
where did u learn to code?