How to Build Calculator App in Python | Project for Beginners | GUI - Tkinter | 1/3

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello everyone welcome to mud codes and today we are going to make a calculator project which will be an executable file and you will be able to run it on your desktop or you can even share it with your friends to use if you aren't already subscribed then do subscribe to my channel for coding and other tech related content in this video we are going to make the calculated gui and get a feel of how the calculator will look so with that let's get started so first we'll create a calculator file and now for this project we're going to use a library called tkinter so for that we'll import it from decanter import star which will include all the sub libraries inside this so to create the calculator window we need to create a screen first so we'll create that like this so now that the screen is created you can see that it's not creating anything like the window is not launching yet that is because we have to run the main loop now so once we run the main loop now you can see that this window pops up over here so this is where the calculator is going to be created now that we've created the main loop let's check over here like as you can see this is still calling it tk and there's a feather item and everything so we need to name it as calculator so for that we will name the title as calculator so screen dot title and then give it calculator and also we need to increase the size because this is very small so for that we will create the geometry screen dot geometry and then we will create the size of the screen as 320 x 447 now i'm creating this specific dimension because i've calculated it already so you can do it accordingly as your screen size and everything so now once that this is done we can see that now the screen is looking like this which is how the calculator screen is going to be now we need to get a result screen over here which will show the output and we need to enter values in it as well so it needs to be like editable so for that we will create a result entry so we'll call it result and we will make it on the screen because we want to display it on the screen and let's keep the background as light gray now we have created the result screen but you won't see it on the display and that is because we haven't placed it anywhere so to place it we need to place the result entry so result.place and i'm using place we can use grid as well but i want all the buttons and all the screens in a very specific area that's why i'm using place so i'll have it at the very top so x equal to 0 y equal to 0 and i want the height to be 60 and width to be the entire width which is 320. so now that i've done this now if i run it this shows the entry part and i can actually enter values over here but as you can see the font and everything is not appropriate so i need to add that as well so i'll add it over here want i'll keep the font as segue ui and i'll keep the size as 20 and make it old because it's the output right and now that we have done this let's run it okay there's some error here okay yeah so now if i run it this is how it comes now one thing that we need to change in the calculator result screen over here is that generally calculator outputs don't come from the left they come from the right like all the outputs always 0 9 and so on right so for that we need to justify to the right for that we'll justify we'll justify to the right and now if we run it and enter values over here it shows it exactly like a calculator now that i've created the result entry i need to create the buttons so for the buttons i've created this specific layout over here and this is how i'm going to create the entire screen for the calculator so for this now i'll start from top left till bottom right so for the first one it's sine so i need to create a button for sine so i'll just create b sine equal to button this is the way we have to define buttons over here and the button is shown on screen so screen and then the text that we want to display on the button is sign and after this we can copy the font from here because we want to maintain consistency but the font size we can reduce a little i'll make it 15. so now that we're done with this button we need to it still won't show because we haven't placed it anywhere so first i will place it b sine dot place and i'll keep it at x equal to 64 y equal to 60 and the height i'll keep as 77 and width as 64. so i'm keeping all the button which says i'll just make button sizes consistent so i'm keeping the button sizes as 64 into 77 this i've done by calculating over here as the result screen is 60 so subtracting and making everything equal this is what the size comes to and it looks normal so otherwise the sizes look very disproportionate now if i run this this is how the sign button looks like so it has come in the center so actually i made a mistake over here x should have been 0 yeah the next x would be 64. so yeah it's in the corner so now similarly i will make buttons for the entire row so the current orientation is five buttons in one row and the next button is root and the text i'll show is square root and x will become 64 because it's shifted by 64 units so i'll do the same for all of them this is open brace and i'll change the positions of all of them by 64 units so this would be 128 this would be 192 and this would be 256 and this button would be division so now if i run it this is our first row and now similarly we'll create all the rows so stay with me on that so i need to change the heights for all of them as the x coordinates will remain same for the next five buttons as i've already mentioned them above i need to change the y coordinate for all of them by 77 so i will add 60 plus 77 which is 137 so i'll add 137 to all of them one two three four five then i need to add 77 again over here it would become two and four one two [Music] three four five then again over here 291 one two three and then 368 for this now i just need to rename all of these buttons so course is over here the next one after cos is 7 so i'll name it b7 now the second row is done i'll do the third row now now we're done with all the buttons let's just check the placement and everything yep they look right so this is how we want them and this is how the calculator gui will look right now the buttons are not functional because we haven't added any functionality to them yet and to see how it's done and how everything is added over here do click on the video on the screen right now thank you
Info
Channel: Mud Codes
Views: 244
Rating: undefined out of 5
Keywords: python, python tutorial, coding, tutorial, python beginner to advance, python for beginners, python projects for resume, python projects, python project for beginners, calculator, calculator project, gui, tkinter, python calculator tutorial, create calculator using python, how to create a calculator using python, create a simple calculator in python, calculator using python, learn javascript, learn python programming for beginners, python calculator, python tutorial for beginners
Id: wqHXnECkliE
Channel Id: undefined
Length: 11min 39sec (699 seconds)
Published: Tue Sep 21 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.