Finish Building A Simple Calculator App - Python Tkinter GUI Tutorial #7

  Рет қаралды 115,986

Codemy.com

Codemy.com

Күн бұрын

Пікірлер: 280
@Codemycom
@Codemycom 4 жыл бұрын
▶️ Watch Entire Tkinter Playlist ✅ Subscribe To My KZbin Channel: bit.ly/2UFLKgj bit.ly/2IGzvOR ▶️ See More At: ✅ Join My Facebook Group: Codemy.com bit.ly/2GFmOBz ▶️ Learn to Code at Codemy.com ✅ Buy a Codemy T-Shirt! Take $30 off with coupon code: youtube1 bit.ly/2VC9WUN
@GavenIsaacs
@GavenIsaacs 5 жыл бұрын
Learning so much. Your down to earth manner ( including non editing out of occasional mistakes ) and good humour makes it all the more enjoyable. So big thanks!
@Codemycom
@Codemycom 5 жыл бұрын
Thanks Gaven, glad you're digging it!
@nikhilbhardwaj2916
@nikhilbhardwaj2916 4 жыл бұрын
I took this calculator making as a challenge. And before watching you, I successfully made it. I grabbed the input as a string using get(). Like "2+6*7" or whatever.. and then using eval(), I calculated the result. That was a little smart calculator 😊... All Thanks To Your Lovely Tutorials.
@Codemycom
@Codemycom 4 жыл бұрын
Nice!
@shivamupadhyay8336
@shivamupadhyay8336 2 жыл бұрын
yea did it with same logic, one line calculator kind
@khushidhingra6524
@khushidhingra6524 4 жыл бұрын
Thank you for providing such videos for 'free'. Loved how you taught us to build the fully functional calculator! But there is are some problems that you might face while using the calculator. You can't perform calculations on floats. And if you divide something by zero it will give you an error. This is how you can solve both of these problems- 1. Just change int into float. 2. You can put the divide function into a try block and perform exception handing on it. Hope this helped you
@EnGentech
@EnGentech Жыл бұрын
how about using float instead of integer as data type and also introducing a decimal point. ?
@luke_miller
@luke_miller 4 жыл бұрын
I tired smashing the like button but ended up breaking my laptop screen. Now I can't code anything. Joking aside, loved the super helpful tutorial!
@Codemycom
@Codemycom 4 жыл бұрын
hahahah thanks!
@sreeharieditography6711
@sreeharieditography6711 4 жыл бұрын
Man you are insane!!!! Hey , can you believe it I developed my own GUI calculator.!!!
@Codemycom
@Codemycom 4 жыл бұрын
Awesome, congratulations!
@mikem8915
@mikem8915 5 жыл бұрын
John, wanted to say ... keep up the good work. Short, sweet, simple ... always a winning formula. This is my first Python GUI effort and I'm glad I took a look. I can already see how to build some simple apps for "admin" type tasks. I haven't looked ahead, but I'm hoping you show us how to package this up for distro. I'm a data engineer so my GUI dev skills are a bit weak. In any case, thanks.
@Codemycom
@Codemycom 5 жыл бұрын
Hey Mike, glad you're enjoying it. I haven't made a video to show how to package it all up and make a distributible file, but I plan on doing that soon.
@adarshtiwari7395
@adarshtiwari7395 4 жыл бұрын
Hey thank you for such helpful and earnest videos. You've been of great assistance in starting to build my logic in using the tkinter module
@Codemycom
@Codemycom 4 жыл бұрын
Glad you enjoyed it!
@johnpro2847
@johnpro2847 5 жыл бұрын
Thanks ...all makes sense ..no classes ..great.Easy conversion for Python 2 or 3
@codyhowell5054
@codyhowell5054 5 жыл бұрын
Best video course on python. super easy to follow and understand
@Codemycom
@Codemycom 5 жыл бұрын
Awesome! Thanks! Glad you're enjoying it!
@sanjaysanjay862
@sanjaysanjay862 4 жыл бұрын
you are the best teacher in the world
@Codemycom
@Codemycom 4 жыл бұрын
Thanks!
@ricardogalvao386
@ricardogalvao386 11 ай бұрын
Olá, sou Brasileiro, estou começando na linguagem Python, estou gostando muito da sua didática, quero aprender mais, parabéns.
@Codemycom
@Codemycom 11 ай бұрын
Thanks, glad you're enjoying them.
@ItalianGenealogy
@ItalianGenealogy 4 жыл бұрын
Great explanation and gave me a few ideas for my own applications. I would suggest, though, that all the repeated code within the button_add, button_subtract, etc. functions be merged into another function to avoid duplication. All you need to do is set the global math in each of them and then hand off to the common function. Thanks for your efforts in explaining Python.
@Codemycom
@Codemycom 4 жыл бұрын
Sure..but for purposes of teaching concepts, I like to keep code as explicit as possible.
@lakshjain7105
@lakshjain7105 4 жыл бұрын
Hi Sir, your work is great and specifically this course is very good and i have been learning tkinter here only. There is a suggestion that you might want to entertain: if you would stay more confident and less doubtful in your codes, that would lead to the students also being confident in your work. Thank You
@Codemycom
@Codemycom 4 жыл бұрын
lol
@mr_k4tz
@mr_k4tz 3 жыл бұрын
I prefer the honesty. It's good to know when your teacher is sure of something or when they are just 'riffing'. In the case of the latter, it's really instructive to hear them go through their thought process, just as JE does in these videos.
@alihabib3201
@alihabib3201 4 жыл бұрын
Beautifully explained. Learning and enjoying alot! Thanks!
@Codemycom
@Codemycom 4 жыл бұрын
Great to hear!
@wingielee
@wingielee 4 жыл бұрын
great tutorials, now am trying to execute all your tkinter projects and i had some issues with the int(f_number) whenever the answer is converted to a float. i decided to use float instead and it works well.. Thanks ones again.
@Codemycom
@Codemycom 4 жыл бұрын
Glad you're enjoying the videos :-)
@meltonenterprises6761
@meltonenterprises6761 4 жыл бұрын
Awesome tutorial!! Thank you for being so helpful. I finally got it all hatched out.
@Codemycom
@Codemycom 4 жыл бұрын
Glad to hear it
@discsanddata6021
@discsanddata6021 4 жыл бұрын
Totally binge watching these right now. Please don't tell everyone how much of a nerd I am...
@Codemycom
@Codemycom 4 жыл бұрын
ha, awesome!
@janpaweii3115
@janpaweii3115 2 жыл бұрын
im chain whatching this tutorial. Its amazing. Thank you for your help
@RonaldModesitt
@RonaldModesitt 2 жыл бұрын
Like button smashed and subscribed. - What a great tutorial!
@siddhantv1
@siddhantv1 4 жыл бұрын
Thank you for your video... I literally have a school project I need to submit tomorrow and your video has helped a lot. Thanks💚 I also smashed the like button :)
@Codemycom
@Codemycom 4 жыл бұрын
Thanks! Good luck with your project!
@ileniavinciguerra5123
@ileniavinciguerra5123 4 жыл бұрын
Great tutorial! It really helped a lot, especially since I'm an absolute beginner. I noticed a small problem: if the user clicks the equal button before doing anything else the program gives an error since we haven't defined this eventuality in the button_equal function and it doesn't recognize the variable 'math'. I solved this by creating another global variable called 'math' at the very first lines of the whole program and gave it the value 0 (it could be any value) so that, if the equal button is pressed with no reason nothing happens and the program doesn't crash. I know there wouldn't be any reason to just randomly click the equal button but it still is a possibily that the users does that so I figured this is a good way to prevent everything from crashing :)
@Codemycom
@Codemycom 4 жыл бұрын
Good idea!
@udhayakumar-zt2dv
@udhayakumar-zt2dv 4 жыл бұрын
I tried to implement what you said. but couln't get it. Can you provide me, what have you exactly implemneted?
@ileniavinciguerra5123
@ileniavinciguerra5123 4 жыл бұрын
@@udhayakumar-zt2dv Before of all the button functions (basically at the very top of the program right after the import and the lines of code that create a window in tkinter) I wrote these lines: "global math math = 0" and then I modified every if statement in the button_equal() function by adding "math = 0" in each body to reset the value of the variable again after each calculation is executed so that, in case the user clicks the equal button before they have inserted numbers at any time, the program doesn't crash. I also realised the crash happens if the operands buttons are clicked before inserting numbers so I fixed that as well by creating another global variable right under the global math one like that "global isclicked isclicked = 0". When a number button is clicked by the user, the button_click() function runs so I added isclicked = 1 in its body and then I added an if statement in every operand function (button_add(), button_divide() etc.) like that "if isclicked != 0:" and then I just indented the rest of the code that is shown in the tutorial so that the computation only takes place if the number buttons are clicked before the operands ones. I then resetted the value of the isclicked variable in the body of the button_equal() function just like I did for the math one so I wrote "isclicked = 0". Hope this helps :)
@ileniavinciguerra5123
@ileniavinciguerra5123 4 жыл бұрын
@@udhayakumar-zt2dv Here is the Repl link if you want to have a closer look repl.it/@ilevinci/Simple-calculator
@ayushshaw3153
@ayushshaw3153 2 жыл бұрын
great tutorials...but for this one i have a question..cant we define global variable math once and use it thorughout in various functions?
@binuscorpia
@binuscorpia 4 жыл бұрын
You are simply great...
@Codemycom
@Codemycom 4 жыл бұрын
Thanks!
@varadvithalkj1716
@varadvithalkj1716 4 жыл бұрын
Thanks man , this is the first app i've ever built thanks to you. One Subcriber more!!
@Codemycom
@Codemycom 4 жыл бұрын
Glad you liked it!
@jorgebalagueraespinosa5936
@jorgebalagueraespinosa5936 Жыл бұрын
Gracias profe, excelente trabajo.
@Codemycom
@Codemycom Жыл бұрын
Welcome :-)
@RandomGigabytes48
@RandomGigabytes48 3 жыл бұрын
just made a calculator thanks sir !!
@Codemycom
@Codemycom 3 жыл бұрын
Great job!
@vamprock02
@vamprock02 4 жыл бұрын
sir you are awesome your tutorials are sooo good.
@Codemycom
@Codemycom 4 жыл бұрын
Thanks!
@ansh4786
@ansh4786 3 жыл бұрын
I finally made it but i want to know how to color buttons when we click on them and when they are not clicked also how to color the text please make a video if you haven't or please share the link of video if you've made because its very difficult to find a video from a group of 202 videos. Thank you
@nasrullah9249
@nasrullah9249 4 жыл бұрын
the tutorial is greater than great!
@Codemycom
@Codemycom 4 жыл бұрын
Thanks!
@mardan9111994
@mardan9111994 2 жыл бұрын
Now that's what I call a quality work! Thank you so much, John, I am very new to your channel, but I am enjoying it so much! Already learnt a lot of stuff about GUI through your videos, and I have just started! Keep up the good job, sir! P.S. I was also wondering if there is a way to store a previous operation in a memory by means of consecutive "+" button clicking or smth similar (without clicking "=")? Say for example, I type 2, then +, then 3, then again +, then 4: so that I could get 9 instead of 7. I am not that good with algorythms, however I am learning. Thank you in advance, John!
@Codemycom
@Codemycom 2 жыл бұрын
Glad you're enjoying the videos! Sure you could assign them to variables if you want to keep track of them.
@aakashdeep6754
@aakashdeep6754 4 жыл бұрын
Thanks for the tutorial. It was great.
@Codemycom
@Codemycom 4 жыл бұрын
Glad it was helpful!
@harikrishnan5756
@harikrishnan5756 3 жыл бұрын
മച്ചാൻ പൊളി 😍
@Codemycom
@Codemycom 3 жыл бұрын
:-)
@JollyAZ
@JollyAZ 5 жыл бұрын
Thank you so much for this tutorial it taught me a lot
@Codemycom
@Codemycom 5 жыл бұрын
So glad you enjoyed it! Thanks for watching!
@Manish_Kumar_04
@Manish_Kumar_04 4 жыл бұрын
Thanks a lot!!, I've successfully made it
@Codemycom
@Codemycom 4 жыл бұрын
Great job!
@GHOST-qg1em
@GHOST-qg1em 5 жыл бұрын
this video helped me a lot, thank you sir.
@Codemycom
@Codemycom 5 жыл бұрын
Glad you liked it!
@karlobucic4412
@karlobucic4412 4 жыл бұрын
Hello from Croatia - 🇭🇷 First, I just want to say that I love your videos. I think that your explaining skills are a great. Second - I have a question : I built my calculator and everything works perfect but I want to know how the Entry widget recognizes "123" as one number and not as three numbers - "1" , "2" , "3". Is that just how it works or what ? Because we don't need to code anything for it to do that.
@shivambhatt5856
@shivambhatt5856 4 жыл бұрын
As we're storing those newly entered values to a variables that into a variable....Nd thus if u enter a "2" after a "1" it becomes 12....nd the interpreter as default takes the whole input for further processing. Hope it satisfies:)
@karlobucic4412
@karlobucic4412 4 жыл бұрын
@@shivambhatt5856 Thanks you so much for the answer. It's going to help me with my project.
@shivambhatt5856
@shivambhatt5856 4 жыл бұрын
@@karlobucic4412 My pleasure! Btw All The Best for your project! ;)
@theophinjohnson8234
@theophinjohnson8234 4 жыл бұрын
Great work buddy
@Codemycom
@Codemycom 4 жыл бұрын
Thanks
@ganesdipa6855
@ganesdipa6855 4 жыл бұрын
Hi, i suggest use eval function for less the code. Thanks for you teach me
@Codemycom
@Codemycom 4 жыл бұрын
Sorry, I don't have a video on that
@nima.sayadi
@nima.sayadi 4 жыл бұрын
Very nice video keep up the good work . I have a question however . How to subtract or divide or... many numbers ? Like 1+4+8+4 without clicking equal button . Any suggestion ?
@sanjaysanjay862
@sanjaysanjay862 4 жыл бұрын
simply AWESOME:)
@Codemycom
@Codemycom 4 жыл бұрын
I appreciate that!
@rehanrimsha1774
@rehanrimsha1774 Жыл бұрын
Is there any way to input decimal digits in this calculator?
@koushikpurusoth3768
@koushikpurusoth3768 4 жыл бұрын
watch this with 2x speed , still you can understand. cool and fast !
@Codemycom
@Codemycom 4 жыл бұрын
whatever floats your boat lol
@crossfarm4146
@crossfarm4146 4 жыл бұрын
Before you I watched this video, I attempted to accomplish this via my own problem solving skills. I literally attempted the exact same strategy, except instead of using a string variable, I used a boolean, so instead of math='addition', I did addition=True. I cant wrap my head around why it wont work, I'm sure there is something weird going on under the hood. Did I possibly just code something wrong using this strategy? or if you try this exact same method using Booleans, it causes some type of error?
@Codemycom
@Codemycom 4 жыл бұрын
Who knows, maybe there was just a typo in your code or something.
@raphaelmonteiro4833
@raphaelmonteiro4833 4 жыл бұрын
The internal command PhotoImage works fine for me using png file. I cound not compile with PIL using pyinstaller, so I tried PhotoImage.
@Codemycom
@Codemycom 4 жыл бұрын
Pyinstaller? Why would you do that? Just pip install Pillow
@raphaelmonteiro4833
@raphaelmonteiro4833 4 жыл бұрын
@@Codemycom to build the code.
@raphaelmonteiro4833
@raphaelmonteiro4833 4 жыл бұрын
@@Codemycom Well. Photo Image works with PNG and I thought that it was the problem that makes everybody uses pillow. The thing is I was not able to build using pyinstaller + PIL or pillow, so I use a internal tkinter function instead of use another external module. But if it has some problem, pls tel me. I dont know what kind of trouble that function could cause.
@Codemycom
@Codemycom 4 жыл бұрын
@@raphaelmonteiro4833 You don't have to build anything. Just pip install Pillow from the terminal
@ekirigwejames
@ekirigwejames 4 жыл бұрын
I was wondering if its right to have the same identifier for both a button object and a function e.g button_equal = Button(...), also def button_equal(): .... You have the same thing for button_add, button_subtract etc.
@Codemycom
@Codemycom 4 жыл бұрын
probably not a great idea
@w.e.a.k.9768
@w.e.a.k.9768 5 жыл бұрын
thanks dude for the lesson dude! but i got a problem with the math variable, it prevent me from using function from math directory. maybe i should change that with another word
@Codemycom
@Codemycom 5 жыл бұрын
There might be an error in your code.
@ChadFi
@ChadFi 4 жыл бұрын
I had the same experience. I changed ‘math’ to ‘art’ and the code worked.
@utkarshchaubey-q9p
@utkarshchaubey-q9p Жыл бұрын
nice explaination
@Codemycom
@Codemycom Жыл бұрын
Thanks
@abdullahmohsen8866
@abdullahmohsen8866 4 жыл бұрын
thanks man, that was great but there is only one problem, when I for example add 2 + 3 it equals 5 and that's nice, but when the process is done and i kept pressing the equal button it will keep adding numbers by itself. will be grateful if you told me why is that and how to fix it
@wraksyt9126
@wraksyt9126 4 жыл бұрын
Thanksss😍♥
@Codemycom
@Codemycom 4 жыл бұрын
Welcome!
@Kaisen947
@Kaisen947 5 жыл бұрын
I am really grateful for this tutorial but it could have been easier
@deepakchowdary1253
@deepakchowdary1253 3 жыл бұрын
stupendous!!
@Codemycom
@Codemycom 3 жыл бұрын
thanks!
@bob_bobsen
@bob_bobsen 3 жыл бұрын
Hey man. Been trying to create an Ans button like on Casio scientific calculators where any time you press '=', you store the value in an Answer variable that can be recalled by the button. How would I port it over to another function?
@Codemycom
@Codemycom 3 жыл бұрын
Any time you store anything in a variable you can send it to another function in the normal way; function(variable)
@ihsankamil420
@ihsankamil420 3 жыл бұрын
Thank you so much!
@Codemycom
@Codemycom 3 жыл бұрын
Thanks for watching!
@rezwanzakaria1754
@rezwanzakaria1754 4 жыл бұрын
can you please tell me what happens in the following lines: def button_click(number): current = e.get() e.delete(0, END) e.insert(0, str(current) + str(number)) My thinking is when I press the number 5 it will store it in "current" variable then insert str(current) + str(number) . Here both current, number has the same indentity (i.e. 5) . So shouldnt we get 55 by pressing the button once?
@Codemycom
@Codemycom 4 жыл бұрын
sounds right...run the code and see for yourself
@tontsa28
@tontsa28 4 жыл бұрын
Your coding videos are simply the best! But I have one question: is it possible to place a button for two rows (vertically)? I'm trying to put an exit button vertically, like for both rows 5 and 6, for the column 0, but it doesn't work? There are buttons on both rows 5 and 6 and on columns 1 and 2. (sorry for the confusing explanation)
@Codemycom
@Codemycom 4 жыл бұрын
use columnspan=2 or rowspan=2 depending on which direction you want to span
@tontsa28
@tontsa28 4 жыл бұрын
@@Codemycom thanks a ton! It didn't even come up to my mind that something like rowspan exists. I'm such an idiot :D
@Codemycom
@Codemycom 4 жыл бұрын
@@tontsa28 That's why I'm here :-)
@alemiggaming4140
@alemiggaming4140 4 жыл бұрын
How can I make the calculator in a way where after you click equals, the first thing you type in AFTER that removes the answer to the previous problem, instead of always having to click clear afterwards?
@rajeshyadlapalli5238
@rajeshyadlapalli5238 2 жыл бұрын
Do we have any GitHub repo link to see the code ?
@Codemycom
@Codemycom 2 жыл бұрын
github.com/flatplanet/Intro-To-TKinter-KZbin-Course
@DisgruntledVet
@DisgruntledVet 4 жыл бұрын
When I tried to add, subtract, divide, or multiply the answer from a division answer that was a decimal, I would get an error. I changed all the int to float and now its all fine.
@Codemycom
@Codemycom 4 жыл бұрын
yep
@jonathanameyo3608
@jonathanameyo3608 4 жыл бұрын
Thanks man you really helped
@armymantv3972
@armymantv3972 4 жыл бұрын
when i try to run the program it keeps saying first_number is not defined. I don't know what I'm doing wrong here
@Codemycom
@Codemycom 4 жыл бұрын
You need to define first_number :-p
@douglasmonteiro3085
@douglasmonteiro3085 5 жыл бұрын
Hi John I have been playing around with creation of buttons and trying to insert new functions, but failed in the Square Root thing HAHA. I - from math import * and the .sqrt functions seems to be fine to use. however I can't make it work. any tips ? I appreciate your work. I have been learning alot. thanks
@Codemycom
@Codemycom 5 жыл бұрын
I'm not sure what you're asking about, but this will work: from math import * print (sqrt(16))
@sunilkjha3638
@sunilkjha3638 4 жыл бұрын
Hello John..... I tried to edit the calculator...and after that in the main output, All the buttons are faraway from each other: Code: from tkinter import * root = Tk() root.title('CALC') e=Entry(root, font=('arial',20,'bold'), width=35, borderwidth=30 , insertwidth=4, bg='powder blue', justify='right') e.grid(columnspan=4) def button_clk(number): # e.delete(0, END) current = e.get() e.delete(0, END) e.insert(0,str(current)+str(number)) def button_clear(): e.delete(0, END) def button_add(): first_number=e.get() global f_num global math math="addition" f_num = int(first_number) e.delete(0, END) def button_equal(): second_number=e.get() e.delete(0,END) if math =="addition": e.insert(0, f_num + int(second_number)) if math =="subtraction": e.insert(0, f_num - int(second_number)) if math =="multiplication": e.insert(0, f_num * int(second_number)) if math =="division": e.insert(0, f_num / int(second_number)) def button_subtract(): first_number = e.get() global f_num global math math = "subtraction" f_num = int(first_number) e.delete(0, END) def button_multiply(): first_number = e.get() global f_num global math math = "multiplication" f_num = int(first_number) e.delete(0, END) def button_divide(): first_number = e.get() global f_num global math math = "division" f_num = int(first_number) e.delete(0, END) #Define the buttons button_1 = Button(root, text="1",font=('arial',20,'bold'),bd=8, fg='black', bg='powder blue',padx=16,pady=16,command=lambda:button_clk(1)) button_2 = Button(root, text="2",font=('arial',20,'bold'),bd=8,fg='black',bg='powder blue',padx=16,pady=16,command=lambda:button_clk(2)) button_3 = Button(root, text="3",font=('arial',20,'bold'),bd=8,fg='black',bg='powder blue',padx=16,pady=16,command=lambda:button_clk(3)) button_4 = Button(root, text="4",font=('arial',20,'bold'),bd=8,fg='black',bg='powder blue',padx=16,pady=16,command=lambda:button_clk(4)) button_5 = Button(root, text="5",font=('arial',20,'bold'),bd=8,fg='black',bg='powder blue',padx=16,pady=16,command=lambda:button_clk(5)) button_6 = Button(root, text="6",font=('arial',20,'bold'),bd=8,fg='black',bg='powder blue',padx=16,pady=16,command=lambda:button_clk(6)) button_7 = Button(root, text="7",font=('arial',20,'bold'),bd=8,fg='black',bg='powder blue',padx=16,pady=16,command=lambda:button_clk(7)) button_8 = Button(root, text="8",font=('arial',20,'bold'),bd=8,fg='black',bg='powder blue',padx=16,pady=16,command=lambda:button_clk(8)) button_9 = Button(root, text="9",font=('arial',20,'bold'),bd=8,fg='black',bg='powder blue',padx=16,pady=16,command=lambda:button_clk(9)) button_0 = Button(root, text="0",font=('arial',20,'bold'),bd=8,fg='black',bg='powder blue',padx=16,pady=16,command=lambda:button_clk(0)) button_add= Button(root, text="+",font=('arial',20,'bold'),bd=8,fg='black',bg='powder blue',padx=16,pady=16,command=button_add) button_equal = Button(root, text="=",font=('arial',20,'bold'),bd=8,fg='black',bg='powder blue',padx=16,pady=16,command=button_equal) button_clear = Button(root, text="C",font=('arial',20,'bold'),bd=8,fg='black',bg='powder blue',padx=16,pady=16,command=button_clear) button_subtract= Button(root, text="-",font=('arial',20,'bold'),bd=8,fg='black',bg='powder blue',padx=16,pady=16,command=button_subtract) button_multiply= Button(root, text="x",font=('arial',20,'bold'),bd=8,fg='black',bg='powder blue',padx=16,pady=16,command=button_multiply) button_divide= Button(root, text="/",font=('arial',20,'bold'),bd=8,fg='black',bg='powder blue',padx=16,pady=16,command=button_divide) #Put the buttons on the screen button_1.grid(row= 3, column=0) button_2.grid(row= 3, column=1) button_3.grid(row= 3, column=2) button_multiply.grid(row=3,column=3) button_4.grid(row= 2, column=0) button_5.grid(row= 2, column=1) button_6.grid(row= 2, column=2) button_subtract.grid(row=2, column=3) button_7.grid(row=1 , column=0) button_8.grid(row=1 , column=1) button_9.grid(row=1 , column=2) button_add.grid(row=1,column=3) button_0.grid(row=4, column=0) button_clear.grid(row=4,column=1) button_equal.grid(row=4,column=2) button_divide.grid(row=4,column=3) root.mainloop()
@Codemycom
@Codemycom 4 жыл бұрын
you gave them padx and pady's of 16 each
@triptypes
@triptypes 4 жыл бұрын
Hi Dear John.İn this calculator result for example 10/2+6 or 21*2+5 not correctly.Please give me answer:)Thanks
@larsdierickx7543
@larsdierickx7543 2 жыл бұрын
How do i add comma's in the input like a extra button ',' and make it work?
@Codemycom
@Codemycom 2 жыл бұрын
Sorry, not sure what you mean
@frall2294
@frall2294 4 жыл бұрын
How should I define point button for example if I want to write 5.25 * 70.56789 ?
@Codemycom
@Codemycom 4 жыл бұрын
Just use floats instead of ints
@subramaniantr2091
@subramaniantr2091 4 жыл бұрын
Hi I've been following this with a few experiments from my side as well. I was trying to make another class which inherited the existing button class. The intention was you have certain common settings for all the buttons. I was thinking of click function as well in the class which would take the text of the button and put it in the entry box. Could you please tell what could be the syntax for the command. I tried putting (self).click, as mentioned in some link. But it doesn't seem to work. I would have to pass the word self to the function click in order to make it work which is not accepted as "self" isn't getting recognised.
@Codemycom
@Codemycom 4 жыл бұрын
Sorry, not sure what you mean
@SenthilManikandan
@SenthilManikandan 4 жыл бұрын
Tkinter itself uses "mixin" classes to "internalize" and handle the requests, but when you create your button class it does not inherit from tkinter superclass and hence self won't be recognised when you try to pass it to a button class inherited from tkinter base class.
@akramelomrani8728
@akramelomrani8728 4 жыл бұрын
you are so good
@Codemycom
@Codemycom 4 жыл бұрын
Thanks!
@DavSetYT
@DavSetYT 2 жыл бұрын
And how can we do when we divide a number by zero?
@anandhakrishnan7354
@anandhakrishnan7354 4 жыл бұрын
Thanks for the tutorial. I would like to ask a question. Instead of using the (global f_num and global math) as a global variable inside each function, why can't we have this outside the function? because it is a global variable right ? just had this doubt. pls, clarify me. It would be great.
@Codemycom
@Codemycom 4 жыл бұрын
Try it and see. There are always multiple ways of doing things
@princegupta8022
@princegupta8022 4 жыл бұрын
It not show output by declaring variable outside the function... What about your code?
@Codemycom
@Codemycom 4 жыл бұрын
@@princegupta8022 Sorry, I don't know what you mean
@princegupta8022
@princegupta8022 4 жыл бұрын
@@Codemycom when I declare variables globally like this Math =StringVar() f_num = IntVar() Calculator not give any output?
@SenthilManikandan
@SenthilManikandan 4 жыл бұрын
@@princegupta8022 Global variables have to be declared global within the function. Otherwise python recognizes it as another variable.
@sean9584
@sean9584 4 жыл бұрын
Does anyone happen to know why *global f_num* and *global math* are returning *is not defined in the global scope* errors? I followed the tutorial step-by-step but always end up with the same error. FYSA: My calculator works with the errors, but don't know why.
@wl7573
@wl7573 3 жыл бұрын
awesome!
@Codemycom
@Codemycom 3 жыл бұрын
Thanks!
@sannihith4204
@sannihith4204 4 жыл бұрын
3 test cases were not passing like 2+3+4= it fails and if we click2+ and then hit clear the enter 3= it gives 5 and 2= also fails !! can anyone suggest how to rectify those
@infinitespace1982
@infinitespace1982 4 жыл бұрын
For some reason my program registers when I want to add numbers, but it doesn't register the other operations (* / -) and just deletes whatever is in the data entry box.
@Codemycom
@Codemycom 4 жыл бұрын
Very weird...
@_89_shrutikumari85
@_89_shrutikumari85 4 жыл бұрын
Sir I need a code to add factorial button in calculator... Plzz help... I tried so many times
@tomporter2164
@tomporter2164 4 жыл бұрын
great tutorials
@Codemycom
@Codemycom 4 жыл бұрын
Thanks! Glad you like them.
@talhazulfiqar571
@talhazulfiqar571 4 жыл бұрын
Thanks man
@Codemycom
@Codemycom 4 жыл бұрын
No problem
@aryanvaghasiya2342
@aryanvaghasiya2342 4 жыл бұрын
Can we add Circle buttons instead of Square ?
@Codemycom
@Codemycom 4 жыл бұрын
Yes, I have videos on that in the playlist
@aryanvaghasiya2342
@aryanvaghasiya2342 4 жыл бұрын
@@Codemycom ooh, thanks for the reply.👍
@arunbeckham8384
@arunbeckham8384 4 жыл бұрын
Hai!! i am getting error near def button_substract(): return. What to do to rectify?
@Codemycom
@Codemycom 4 жыл бұрын
What's the whole error?
@arunbeckham8384
@arunbeckham8384 4 жыл бұрын
@@Codemycom unindent doesn't match
@Codemycom
@Codemycom 4 жыл бұрын
@@arunbeckham8384 Indentation has to be exactly as I do in the video.
@elpatron6156
@elpatron6156 4 жыл бұрын
Can I ask you a question? I want to make square root button work, but every time when I make a function and when I press the button, it doesn't work. Can you tell me why?
@Codemycom
@Codemycom 4 жыл бұрын
Not without seeing your code
@tapeshvashisth7726
@tapeshvashisth7726 4 жыл бұрын
Please help me sir!!! I made calculator of my own but when i am using int with get() as you have done, then i am getting the following error invalid literal for int with base 10 but your works fine with it.. Please help
@Codemycom
@Codemycom 4 жыл бұрын
Check your code for typos. It has to be exact
@tapeshvashisth7726
@tapeshvashisth7726 4 жыл бұрын
Sir I got my mistake . My mistake for that while creating buttons I wrote text="5" and because of this I was not able to convert it to int type but now it's fixed😂😂😂
@Codemycom
@Codemycom 4 жыл бұрын
@@tapeshvashisth7726 Glad you figured it out :-)
@vishalkumaresan8420
@vishalkumaresan8420 4 жыл бұрын
great model, but i am confused on adding functions like square root in this program
@Codemycom
@Codemycom 4 жыл бұрын
Confused how?
@vishalkumaresan8420
@vishalkumaresan8420 4 жыл бұрын
@@Codemycom what should be the logic for it...I do it with math function sqrt, but I get an error called sqrt is not declared
@Codemycom
@Codemycom 4 жыл бұрын
@@vishalkumaresan8420 You need to import math: import math math.sqrt(12) where 12 is whatever you want to calculate
@aneeshmalapaka8363
@aneeshmalapaka8363 4 жыл бұрын
hey can anyone help me with printing exceptions the entry widget...like when u divide by zero,u get nothing so i wanna print out cannot divide by zero....any ideas how??
@Codemycom
@Codemycom 4 жыл бұрын
Use an if statement to determine if they are trying to divide by zero, and IF so, output your message.
@aneeshmalapaka8363
@aneeshmalapaka8363 4 жыл бұрын
That was the first thing i did but the output msg is not printing...like if i say, if math=="division" and second number ==0 : (at this step i tried, e.insert, print, but it is blank...i will try again and notify..)
@tor6953
@tor6953 Жыл бұрын
Thank you
@Codemycom
@Codemycom Жыл бұрын
Welcome
@johnpro2847
@johnpro2847 4 жыл бұрын
how to make numbers appear on right side like as in real calculators ?
@Codemycom
@Codemycom 4 жыл бұрын
real calculators?
@sahejsingh9732
@sahejsingh9732 4 жыл бұрын
e = Entry(root, justify=RIGHT) by using justify=RIGHT the numbers will appear on right side
@BiquiRaccoon
@BiquiRaccoon 4 жыл бұрын
I did exactly same coding with yours. But I keep getting this error [AttributeError: 'Button' object has no attribute 'gird'] I did googling but I can't figure out what is problem. Can you help me?
@Codemycom
@Codemycom 4 жыл бұрын
You misspelled grid, you spelled it gird.
@sohaibss8073
@sohaibss8073 4 жыл бұрын
Hi i want to make this calculator ready for use to user , when he need to use this calculator i want him just clique on a file or something and this calculator show up
@Codemycom
@Codemycom 4 жыл бұрын
I have a video in this playlist that shows you how to create an executable exe file.
@kpoornodaysriram5568
@kpoornodaysriram5568 Жыл бұрын
While running the code , The columns are showing gap in between eachother
@Codemycom
@Codemycom Жыл бұрын
What did you do differently from the video?
@اصنعهابنفسك-ر8م
@اصنعهابنفسك-ر8م 4 жыл бұрын
I have a problem with this line it stile say to me something wrong in this line Button_1=Button(root, text="1", padx=40, pady=20, command=Lambda: Button_click(1))
@Codemycom
@Codemycom 4 жыл бұрын
Lambda should not be capitalized.
@musakayasimp6456
@musakayasimp6456 4 жыл бұрын
hello i just wanted to say that i followed the steps step by step but when i finished it says that f_num is not defined please Help
@Codemycom
@Codemycom 4 жыл бұрын
You missed a step then. Check your code.
@tinotendagarwe4929
@tinotendagarwe4929 Жыл бұрын
one thing i noticed is you keep repeating code like cant we inherit and use functions such as eval() instead the if statement
@Codemycom
@Codemycom Жыл бұрын
of course you can do whatever you want. I repeat code to be explicit as I can so people easily learn.
@jonathanameyo3608
@jonathanameyo3608 4 жыл бұрын
Hello Codemy, with this code i don't understand why it it is duplicating my answer eg if I say 2+3 answer is supposed to be 5 but mine is saying 55.Please assist me or anyone who knows what my problem is?
@Codemycom
@Codemycom 4 жыл бұрын
rewatch the video, I address that
@ipyb4u
@ipyb4u 4 жыл бұрын
My program isnt working right, the subtract button isnt showing up?
@Codemycom
@Codemycom 4 жыл бұрын
Check your code for typos..it has to be exact
@farookk4744
@farookk4744 4 жыл бұрын
Why don't you use an IDE instead of using both text editor and terminal
@farookk4744
@farookk4744 4 жыл бұрын
Still the videos are fruitful
@Codemycom
@Codemycom 4 жыл бұрын
@@farookk4744 Because this way is easy for beginners and it's free. Everyone has access to these tools with no need to learn a complicated IDE.
@ritishanand2668
@ritishanand2668 4 жыл бұрын
How do i make the decimal button (" . ") work?
@Codemycom
@Codemycom 4 жыл бұрын
?
@ritishanand2668
@ritishanand2668 4 жыл бұрын
@@Codemycom like how do I get to add 1.1 + 1.2
@Codemycom
@Codemycom 4 жыл бұрын
@@ritishanand2668 Create a '.' button and concatenate...I don't cover this in the videos but it couldn't be hard. Give it a try..
@sarthaksrivastava6282
@sarthaksrivastava6282 4 жыл бұрын
also you have to limit the number of times one can click on the decimal button as it can't be used more than once for an input
@Codemycom
@Codemycom 4 жыл бұрын
@@sarthaksrivastava6282 Good point
@pimmpoll1471
@pimmpoll1471 4 жыл бұрын
Getting confused, how did the calculator know that it needs to multiply or divide? The global variable math is only been given a string which "substract" etc...
@nileshgaikwad4175
@nileshgaikwad4175 3 жыл бұрын
for example: when you are pressing '/' button, the command is function button_divide, in that function math == division. I am also a beginner and thought over your question.
@pimmpoll1471
@pimmpoll1471 3 жыл бұрын
@@nileshgaikwad4175 Thanks
@manisankarchittela1241
@manisankarchittela1241 4 жыл бұрын
Pycharm shows error=5 nd no interpreter found any solution to solve the error
@Codemycom
@Codemycom 4 жыл бұрын
Sorry, I don't use pycharm. I suggest you use the tools I use, sublime text and git bash editor.
@sahejsingh9732
@sahejsingh9732 4 жыл бұрын
it would be better if you have used "eval" function but i was the best tutorial
@Codemycom
@Codemycom 4 жыл бұрын
better is relative :-p
@RufusVidS
@RufusVidS 2 жыл бұрын
Codemy prices have gone up substantially since this recording. The $27 mentioned (with discount) only covers ONE course ($29 actually), not ALL the courses as stated in the video. I am not saying the new price is not worth it, but it's an investment for me I don't want to pay that for just a single course either.
@harishraghavans3381
@harishraghavans3381 3 жыл бұрын
How can I include cancel button
@Codemycom
@Codemycom 3 жыл бұрын
I have videos on buttons all over the playlist
@frall2294
@frall2294 4 жыл бұрын
if math == "addition" SyntaxError: invalid syntax What should I do?
@Codemycom
@Codemycom 4 жыл бұрын
You need a colon after "addition":
@frall2294
@frall2294 4 жыл бұрын
@@Codemycom thank you soo much
@Codemycom
@Codemycom 4 жыл бұрын
@@frall2294 Sure thing!
«Жат бауыр» телехикаясы І 26-бөлім
52:18
Qazaqstan TV / Қазақстан Ұлттық Арнасы
Рет қаралды 434 М.
Хаги Ваги говорит разными голосами
0:22
Фани Хани
Рет қаралды 2,2 МЛН
GIANT Gummy Worm #shorts
0:42
Mr DegrEE
Рет қаралды 152 МЛН
Build A Simple Calculator App - Python Tkinter GUI Tutorial #5
18:05
How to make a Calculator in Python using tkinter
7:45
Koolac
Рет қаралды 11 М.
Modern Graphical User Interfaces in Python
11:12
NeuralNine
Рет қаралды 1,6 МЛН
Create Stunning Python GUIs in 10 Minutes With Drag & Drop
11:38
Coding Is Fun
Рет қаралды 108 М.
5 Useful F-String Tricks In Python
10:02
Indently
Рет қаралды 340 М.
Simple Android Calculator App in Python
21:06
NeuralNine
Рет қаралды 42 М.
Make Tkinter Look 10x Better in 5 Minutes (CustomTkinter)
4:40
TurbineThree
Рет қаралды 367 М.
«Жат бауыр» телехикаясы І 26-бөлім
52:18
Qazaqstan TV / Қазақстан Ұлттық Арнасы
Рет қаралды 434 М.