▶️ Watch Entire Tkinter Playlist ✅ Subscribe To My RU-vid 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
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!
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.
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
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.
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.
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.
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
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.
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.
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!
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 ?
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?
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.
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:)
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 :)
@@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 :)
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 :)
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
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)
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?
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.
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
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?
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
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.
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.
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?
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
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.
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?
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?
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?
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.
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.
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.
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
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😂😂😂
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))
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
@@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.
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??
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..)
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...
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.
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
$ python calculator.py File "calculator.py", line 32 e.insert(0, f_num + int(second_number)) ^ TabError: inconsistent use of tabs and spaces in indentation Please Fix This Error John Elder