Continue Building A Simple Calculator App - Python Tkinter GUI Tutorial #6

  Рет қаралды 159,256

Codemy.com

Codemy.com

Күн бұрын

Let's Continue Building A Simple Calculator App. In this video we'll continue to build out our simple calculator app using the stuff we've learned from the previous videos. We'll create the clear button, the add button, and the equal to button functionality in this video.
In this series I'll show you how to create graphical user interfaces for Python with Tkinter. TKinter comes with Python already, so there's nothing to install!
✅ Watch The Other Videos In This Python Playlist:
bit.ly/2UFLKgj
▶️ See More At:
Codemy.com
✅ Join My Facebook Group:
bit.ly/2GFmOBz
✅ Subscribe To My KZbin Channel:
bit.ly/2IGzvOR
▶️ Learn to Code at Codemy.com
Take $22 off with coupon code: youtube

Пікірлер: 364
@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
@donaldppaul3260
@donaldppaul3260 3 жыл бұрын
What does END do
@Codemycom
@Codemycom 3 жыл бұрын
@@donaldppaul3260 What do you think? It ends a thing.
@donaldppaul3260
@donaldppaul3260 3 жыл бұрын
@@Codemycom pls explain why do you use a END in e.insert(END,number)
@100jsj6
@100jsj6 2 жыл бұрын
@@donaldppaul3260 coz he wanted to GET or DELETE from 0 (0 is first value in python if u dont know , so counting in py is 0,1,2,3 etc ) to the END of the string
@Tinker250
@Tinker250 Жыл бұрын
@@Codemycom I keep on getting a error "NameError: name 'f_num' is not defined" this is part of my script can someone help me fix it def button_add(): first_number = e.get() global f_num f_num = int(first_number) e.delete(0, END) def button_equal(): second_number = e.get() e.delete(0, END) e.insert(0, f_num + int(second_number))
@josephsevita5863
@josephsevita5863 3 жыл бұрын
You're genuine. This is how we code, making mistakes, hoping it runs, too many edited videos making the programmer look perfect, no syntax errors, never a question on how an API works. This should inspire aspiring programmers. Thanks.
@Codemycom
@Codemycom 3 жыл бұрын
Thanks! Glad you like it!
@user-me8es9tv9n
@user-me8es9tv9n 4 жыл бұрын
1:10 On the 13th line you could write 'END' insead of 0 and it'll be working.
@ty-is5xv
@ty-is5xv 4 жыл бұрын
nichego sebe
@kjn5991
@kjn5991 4 жыл бұрын
Yes, I was about to say the same thing. Much simpler way.
@user-br4qn2sn4v
@user-br4qn2sn4v 4 жыл бұрын
try with a capital letters,i tried and its work
@ozbekchawindows4236
@ozbekchawindows4236 4 жыл бұрын
Yes, I'm agree with you!
@NOAHBENJ
@NOAHBENJ 3 жыл бұрын
Genius. Just Genius
@Gvk795
@Gvk795 5 жыл бұрын
"I'm just making this up as I go, you can tell." Made me laugh. Thank you for the video series this is very helpful and fun!
@Codemycom
@Codemycom 5 жыл бұрын
ha, glad you're enjoying it!
@mrunixman1579
@mrunixman1579 4 ай бұрын
Great video, this came in handy for my college project which requires python and Tkinter. Even my college tutor makes many mistakes in his program.
@Codemycom
@Codemycom 4 ай бұрын
Happy to hear it!
@helio6540
@helio6540 2 жыл бұрын
Hello from Brazil. I decided to learn some python, and I realized that the best way to learn something is use this something in a project. So I opened 10 youtube videos on "how to make a simple calculator with python", and after watching one of you videos I closed all the others. The way you explain things is very interesting, thanks for the amazing tutorials.
@Codemycom
@Codemycom 2 жыл бұрын
Glad you enjoyed it!
@markblair1655
@markblair1655 4 жыл бұрын
This is the best library introduction series of all time, seriously. The way you present and show things allows us to not only understand it, but to be able to create and implement into our own ideas immediately. Cannot thank you enough for your videos.
@Codemycom
@Codemycom 4 жыл бұрын
Wow thanks! That's high praise! Glad you're enjoying them...
@daveandpamwilkinson3883
@daveandpamwilkinson3883 4 жыл бұрын
Dude you are bloody brilliant. I will buy yours courses. Loving this!
@Codemycom
@Codemycom 4 жыл бұрын
Awesome, glad you like it!
@mrawesome7739
@mrawesome7739 3 жыл бұрын
I can't believe that I have 170 more amazing videos to watch!
@Codemycom
@Codemycom 3 жыл бұрын
Enjoy!
@jelayneds2422
@jelayneds2422 4 жыл бұрын
So helpful! Thank you!
@Codemycom
@Codemycom 4 жыл бұрын
Glad you liked it Angelaine!
@parsabahrambeik4381
@parsabahrambeik4381 3 жыл бұрын
Hi, the videos are all good, thank you very much.
@aminmech
@aminmech Жыл бұрын
The best tkinter Tutorial in the youtube.
@Codemycom
@Codemycom Жыл бұрын
Thanks!
@EpicBURN321
@EpicBURN321 4 жыл бұрын
A really simple way of fixing the calculator number input issue is to change "e.insert(0, number)" to "e.insert(END, number)". This eliminates the need for a "current" variable and the string concatenation
@parfaitmombo966
@parfaitmombo966 4 жыл бұрын
Thanks, it worked.
@marcmathieutrance6807
@marcmathieutrance6807 2 жыл бұрын
I like your reaction when your code runs! lol
@kameenabandar3772
@kameenabandar3772 3 жыл бұрын
We can also create a variable i and pass it in e.insert(i,number) and increment it each time for correct representation Then while clearing reset the value of i to 0 This worked pretty well
@jorgebalagueraespinosa5936
@jorgebalagueraespinosa5936 Жыл бұрын
Gracias profe, saludos desde Bucaramanga-Colombia
@Codemycom
@Codemycom Жыл бұрын
Welcome
@lonxwolx
@lonxwolx 2 жыл бұрын
thank you for this. helps a lot!
@Codemycom
@Codemycom 2 жыл бұрын
Glad to hear it!
@user-ik2pj7ch1n
@user-ik2pj7ch1n 2 жыл бұрын
To how want's to learn python easy this good chanel لكل من يريد تعلم بايتون هذه القناة افضلل مكان للتعلم. شكرا كثيرا thanks lot
@Codemycom
@Codemycom 2 жыл бұрын
Thanks!
@johnpro2847
@johnpro2847 5 жыл бұрын
Thanks ..helpful
@Codemycom
@Codemycom 5 жыл бұрын
Glad to help
@user-hl6cq4jm3l
@user-hl6cq4jm3l 3 жыл бұрын
U are the best programmer. that I saw
@Codemycom
@Codemycom 3 жыл бұрын
Thanks!
@andrejvujic
@andrejvujic 4 жыл бұрын
You could've used the inbuilt string split method for adding numbers, btw thanks for the great tutorial series
@Codemycom
@Codemycom 4 жыл бұрын
Sure, there's always a hundred different ways you can do a thing
@joaoberg3891
@joaoberg3891 2 жыл бұрын
obrigado pelos videos
@umpalumpa2883
@umpalumpa2883 3 жыл бұрын
Would be interesting which other ideas you guys came up with for doing the math. Maybe we can collect them in this thread. I used a little different approach and used result = eval(e.get()) for the equal button. The advantage is, that we can see the calculation all the time. Furthermore we can type in a calculation into the text field (which is of course not the aim of this video).
@SyedAlirazarizvi72
@SyedAlirazarizvi72 2 жыл бұрын
I have used the following technique for adding number in right sequence. def button_click(number): e.insert(len(e.get())+1, number) it's simply adding the value at the end of currently available value.
@monwan
@monwan 3 жыл бұрын
great, thanks
@Codemycom
@Codemycom 3 жыл бұрын
Welcome :-)
@hardikpunj9321
@hardikpunj9321 3 жыл бұрын
We may write a=e.get() e.insert(len(a),num)
@Codemycom
@Codemycom 3 жыл бұрын
sure
@aliabedi-hp8ls
@aliabedi-hp8ls Жыл бұрын
thanks for your video. so informative and efficient. every day i go on with more motivation and strong will. i hope we become expert developers in end and be professional. and i hope to not be taken back or demotivated of this,
@Codemycom
@Codemycom Жыл бұрын
Welcome!
@sasitobs4884
@sasitobs4884 11 ай бұрын
Best web series I am watching right now
@Codemycom
@Codemycom 11 ай бұрын
Happy to hear it!
@hossamketfi9892
@hossamketfi9892 2 жыл бұрын
This channel is so underrated.
@Codemycom
@Codemycom 2 жыл бұрын
Thanks! Tell your friends!
@texxmexxchick
@texxmexxchick 3 жыл бұрын
nice tutorial
@Codemycom
@Codemycom 3 жыл бұрын
Thanks
@tor6953
@tor6953 7 ай бұрын
Thank you
@Codemycom
@Codemycom 7 ай бұрын
Welcome!
@rushey_1771
@rushey_1771 4 жыл бұрын
Thanks bro🤗
@Codemycom
@Codemycom 4 жыл бұрын
sure thing
@rushey_1771
@rushey_1771 4 жыл бұрын
@@Codemycom bro one help: How to provide entry box for only getting integer input??
@christophersantillan3393
@christophersantillan3393 3 жыл бұрын
Great content John! I really appreciate your videos! Does anyone know how to do unit test on GUI? like in this case, how can you make a unit test to verify that the function "def button_add():" works correctly?
@raymondzhao9557
@raymondzhao9557 Жыл бұрын
pretty coooooool
@Codemycom
@Codemycom Жыл бұрын
Thanks!
@user-ou7jn4eb1z
@user-ou7jn4eb1z 5 жыл бұрын
Why we should use lambda to execute the command
@Codemycom
@Codemycom 5 жыл бұрын
Because that's the only way tkinter allows you to pass variables through your function from the button.
@bryanoakley5189
@bryanoakley5189 3 жыл бұрын
@@Codemycom It's not the only way, just a very common way. For example, you could also use functools.partial.
@aaryansachdeva
@aaryansachdeva 10 ай бұрын
I found a more efficient way to insert the numbers on the textfield and only uses 1 line instead of 3: Original: current = e.get() e.delete(0, END) e.insert(0, str(current) + str(number)) My way: e.insert(END, number)
@hectorramsey318
@hectorramsey318 15 күн бұрын
For some reason the exact same code didn't work using PyCharm but worked on VS code, I'm not sure why but otherwise great tutorial I'm loving this so far
@Codemycom
@Codemycom 15 күн бұрын
Because pyCharm is garbage.
@porcelainface7809
@porcelainface7809 3 жыл бұрын
My first thought for doing the addition was to just turn this into a class :P
@Codemycom
@Codemycom 3 жыл бұрын
fun
@MrGrey64
@MrGrey64 Жыл бұрын
So I did something like this: # for the equal button: def calculate_and_print(): try: answer = eval(enter.get()) button_clear() button_click(answer) except(SyntaxError): enter.insert(0, "") And I just passed the button_click function a "+". It worked! In a different way though 😆
@user-ds9ey8pp5h
@user-ds9ey8pp5h 2 жыл бұрын
great
@Codemycom
@Codemycom 2 жыл бұрын
Thanks!
@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.
@lukag0569
@lukag0569 4 жыл бұрын
Tako da ih označiš kao intiger ili float, a ne kao string zato što ako ga program vidi kao string to je isto kao da vidi neku riječ, oprosti ako govorim ovo a već si naučio. intiger(int) je neki cijeli broj float je neki broj koji ima decimalu
@karlobucic4412
@karlobucic4412 4 жыл бұрын
Već sam dovršio projekt no svejedno - puno hvala ! Lijepo je kada znaš da je netko zapravo odvojio svoje vrijeme kako bi ti pomogao / odgovorio. 😃
@mbn-code
@mbn-code 3 жыл бұрын
now playing around with the fx: def button_clear(): thing i thought of making an exit button even tho i kno you can just press in the top corner but, if anyone want a exit button i am very new to coding and python, so this is properbly ugly to some body, but hey this is just about learning and having fun wwith it line 1: def function(exit): pass def button_exit(): button_exit = function(exit()) line 2: button_exit = Button(root, text="exit", padx=40, pady=20, command=button_exit) line 3: button_exit.grid(row=6, column=1, columnspan=1)
@hagaibuachi2166
@hagaibuachi2166 2 жыл бұрын
thank you! can you know how can i create a calculator salary avarage with this?
@Codemycom
@Codemycom 2 жыл бұрын
use basic math
@ahmedlimam2241
@ahmedlimam2241 4 жыл бұрын
For the add and equal buttons you can use something like that : This way you can add multiples numbers not just two (I am using class so just remove "self") self.sm = 0 # sum def btn_add(self): self.sm += int(self.e.get()) self.e.delete(0,END) def btn_eq(self): add = int(self.e.get()) self.e.delete(0,END) self.e.insert(0,self.sm+add) self.sm=0
@Codemycom
@Codemycom 4 жыл бұрын
fun
@AhrenBaderJarvis
@AhrenBaderJarvis 3 жыл бұрын
for button_click instead of deleting the entire entry, and then re-adding it, I just changed the insert position to be len(e.get()), which inputs the button entry after the last character of the textbox. My whole button_click function reads: def button_click(number): e.insert(len(e.get()), number)
@Codemycom
@Codemycom 3 жыл бұрын
cool
@manikandannatarajan9665
@manikandannatarajan9665 3 жыл бұрын
VERY HELPFUL, IM JUST A 13-YEAR-OLD AND I LOVE IT, THANKS A LOT, @PRANAVA AND DO YOU HAVE 1 TO 1 COURSES
@Codemycom
@Codemycom 3 жыл бұрын
Glad you liked it. I don't know what 1 to 1 courses are.
@varadvithalkj1716
@varadvithalkj1716 3 жыл бұрын
@@Codemycom one instructor , one student. Mo' Moneyy!
@Codemycom
@Codemycom 3 жыл бұрын
@@varadvithalkj1716 Not true at all lol one instructor, one student = MASSIVELY LESS money. Lol I'd rather do it the way I do now...one instructor makes a video and 100,000 students watch it lol THAT'S more money lol would you rather have 1 student paying you, or 100,000 students paying you?
@varadvithalkj1716
@varadvithalkj1716 3 жыл бұрын
@@Codemycom i didnt really understand the money part, sorry i thought thats how it worked, but anyways thanks for this amazing seeries tho
@entertainmentdevashishroy2760
@entertainmentdevashishroy2760 3 жыл бұрын
insert all values as string and use eval function. it will be better
@pragunashok6008
@pragunashok6008 3 жыл бұрын
hey i was just wondering is there any way to have a backspace button, which only deletes the last digit??
@Codemycom
@Codemycom 3 жыл бұрын
Sure would just take a little tinkering. You can get the last character of a string with [-1] or you can return everything in a string except the last character with [:-1]....so if your string is named my_string, you can return everything but the last character by calling my_string[:-1] Just set that up in a function that gets called when you click the button...and config it to the entry box or whatever
@hardikpunj9321
@hardikpunj9321 3 жыл бұрын
You may write func like this a=e.get() e.delete(len(a)-1,END)
@fixitalltech1014
@fixitalltech1014 4 жыл бұрын
Created program using same code as your . But I’m not getting the value of the button pressed .in the entry field . Using lambda under command .
@Codemycom
@Codemycom 4 жыл бұрын
Then you have a typo somewhere. Is lambda lowercase?
@amiralasady3725
@amiralasady3725 Жыл бұрын
one ez way is to insert the input number Not on the zeroth position, but at the end of the total length of the hall number elements in the entry by adding +1 like .. def put_num(num): entry_elements=win.get() total_len=len(entry_elements) win.insert(total_len+1,str(num))
@shamailanaimat7347
@shamailanaimat7347 3 жыл бұрын
I NEED HELP! at the very last part of the video where we define the button_equal i keep on this error: line 30, in button_equal e.insert(0, f_num + int(second_number)) TypeError: int() argument must be a string, a bytes-like object or a number, not 'method'
@shamailanaimat7347
@shamailanaimat7347 3 жыл бұрын
Here, i even copied and pasted all the code on my screen so far.. from tkinter import * root = Tk() root.title("Yahya's Addition Calculator") e = Entry(root, width=35, borderwidth=5) e.grid(row=0, column=0, columnspan=3, padx=10, pady=10) def button_click(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 f_num = int(first_number) e.delete(0, END) def button_equal(): second_number = e.get e.delete(0, END) e.insert(0, f_num + int(second_number)) button_1 = Button(root, text="1", padx=40, pady=20, command=lambda: button_click(1)) button_2 = Button(root, text="2", padx=40, pady=20, command=lambda: button_click(2)) button_3 = Button(root, text="3", padx=40, pady=20, command=lambda: button_click(3)) button_4 = Button(root, text="4", padx=40, pady=20, command=lambda: button_click(4)) button_5 = Button(root, text="5", padx=40, pady=20, command=lambda: button_click(5)) button_6 = Button(root, text="6", padx=40, pady=20, command=lambda: button_click(6)) button_7 = Button(root, text="7", padx=40, pady=20, command=lambda: button_click(7)) button_8 = Button(root, text="8", padx=40, pady=20, command=lambda: button_click(8)) button_9 = Button(root, text="9", padx=40, pady=20, command=lambda: button_click(9)) button_0 = Button(root, text="0", padx=40, pady=20, command=lambda: button_click(0)) button_add = Button(root, text="+", padx=39, pady=20, command= button_add) button_equal = Button(root, text="=", padx=91, pady=20, command= button_equal) button_clear = Button(root, text="Clear", padx=79, pady=20, command=button_clear) #place button on screen button_1.grid(row=3, column=0) button_2.grid(row=3, column=1) button_3.grid(row=3 , column=2) button_4.grid(row=2, column=0) button_5.grid(row=2, column=1) button_6.grid(row=2, column=2) button_7.grid(row=1, column=0) button_8.grid(row=1, column=1) button_9.grid(row=1, column=2) button_0.grid(row=4, column=0) button_clear.grid(row=4, column=1, columnspan=2) button_equal.grid(row=5, column=1, columnspan=2) button_add.grid(row=5, column=0 ) root.mainloop()
@Jaocekeo
@Jaocekeo 3 жыл бұрын
@@shamailanaimat7347 the error is in your button_equal function definition, wrong: second_number = e.get correct: second_number = e.get() The problem is that you assigned e.get to second_number, thus making second_number a function equivalent to e.get. whereas you should have assigned e.get() to second_number. which assigns the return value of the e.get() function to your second_number variable.
@kidredglow2060
@kidredglow2060 Жыл бұрын
2:47 if you type click the buttons like this 1,2,3,4,5,6... you get the abacaba sequence!
@a_single_nut
@a_single_nut Жыл бұрын
at 2:10, could you reach the same conclusion by slicing with a -1 step? I came up with the following, was curious if it would still function in the same manner: e.insert(0, num)[::-1]
@Codemycom
@Codemycom Жыл бұрын
try it and see
@rodrigomsvlog
@rodrigomsvlog 3 жыл бұрын
If I wanna write the number 123, to fix the adding problem, I used: def buuton_click(number): e.insert(END, number)
@Abhijeetetrx
@Abhijeetetrx 4 жыл бұрын
Hey there, thanks for this fantastic video series! I'm confused on the logic of this, I'm not understanding how do the numbers print out and not append everytime: def button_click(num): current = e.get() e.delete(0, END) e.insert(0, str(current) + str(num)) Can you please help me on this?
@Codemycom
@Codemycom 4 жыл бұрын
Not sure what you mean
@Abhijeetetrx
@Abhijeetetrx 4 жыл бұрын
@@Codemycom sorry I figured it out now! Had to go through your tutorial 3 times to understand, because I'm a complete noob! :( But I'm getting better now, thanks to your tutorials 😎
@Codemycom
@Codemycom 4 жыл бұрын
@@Abhijeetetrx ah cool, glad you got it sorted out :-)
@kaihinliew2976
@kaihinliew2976 3 жыл бұрын
def button_click(num): e.insert(len(e.get()), num) i found out this will be more easier and it work out the same hope it help you out
@cssflags7771
@cssflags7771 4 жыл бұрын
This is simpliest code for button_click and button_delete: def button_click(number): display.insert(END, number) def button_delete(): last = len(display.get()) display.delete(last - 1, END)
@Codemycom
@Codemycom 4 жыл бұрын
There are always infinite ways to do a thing.
@kindersmith8407
@kindersmith8407 3 жыл бұрын
how do I get the program to close by itself? I mean the X button is pretty clear, but shouldn't import sys and then sys.exit() work? because I have tried and it doesn't really do anything.
@Codemycom
@Codemycom 3 жыл бұрын
root.quit() usually works. root.destroy() might do the trick
@rverm1000
@rverm1000 2 жыл бұрын
How do you do a while loop with the tkinter library
@Codemycom
@Codemycom 2 жыл бұрын
In the same way you do any while loop...it's python, it has nothing to do with tkinter.
@utsavpunia420
@utsavpunia420 3 жыл бұрын
i tried it on my own and i think that the addition algo works for only 2 nos in continuity. like if we do 2+2 it gives 4. but when we do 2+2+2 it still gives 4 because we have used only first and second number... is there any solution to it???
@sarvdeepsangwan1207
@sarvdeepsangwan1207 2 жыл бұрын
store result in a list and when u hit equal to then only process sum of all the element in the list
@utsavpunia420
@utsavpunia420 2 жыл бұрын
@@sarvdeepsangwan1207 okh thank u 👍
@IceTheCoder
@IceTheCoder Жыл бұрын
Can't I just use e.insert(END, number) or is there a problem?
@thehash8
@thehash8 2 жыл бұрын
Thanks for the tutorial. I have a query. If I add 2 numbers e.g. 4+5 answer comes as 9 and if I don't click clear button. the next number I click will display next to 9. like 932. What should I do?
@Codemycom
@Codemycom 2 жыл бұрын
continue watching the videos
@dylanl4802
@dylanl4802 Жыл бұрын
instead of e.delete and all of those other stuff u could have just done e.insert(END, number), it worked well for me i dont know if it is the correct way cause i havent completed my calc yet.
@Codemycom
@Codemycom Жыл бұрын
That just slaps it on the end of the entry box. If there's another number there already it wont work
@user-mh2qc7ox4j
@user-mh2qc7ox4j 4 ай бұрын
Hello , you're amazing , I'm sorry i have a problem , the global variable it doesn't work for me , what's the problem?
@Codemycom
@Codemycom 4 ай бұрын
You used it incorrectly. What did you do differently from the video?
@luciferkhusrao
@luciferkhusrao 3 жыл бұрын
Sir, if we use this e.insert(END,number), then we can do it in just 1 line
@Codemycom
@Codemycom 3 жыл бұрын
yeah
@moosman3527
@moosman3527 3 жыл бұрын
you can out the two numbers in a list and add them together
@Codemycom
@Codemycom 3 жыл бұрын
Sure
@_Cartographer_
@_Cartographer_ 3 жыл бұрын
5:00 why did he remove the brackets from in front of the function, don't we need them to call a function ?
@khareek2453
@khareek2453 3 жыл бұрын
Because the clear button calls a function that doesn't require a parameter. Therefore no lambda and no brackets are needed :)
@user-me8es9tv9n
@user-me8es9tv9n 3 жыл бұрын
it calls a void
@ritusree05
@ritusree05 3 жыл бұрын
Sir while executing the stuff the system said that 'padx' is not defined. How should I fix that?
@Codemycom
@Codemycom 3 жыл бұрын
check your code for typos. It has to be exact
@johankotze42
@johankotze42 4 жыл бұрын
In button_click I did: e.insert( len( e.get() ) , digit ) to address that incorrect order.
@user-sq6zm6wk3y
@user-sq6zm6wk3y 4 жыл бұрын
e.insert( END , digit )
@user-sq6zm6wk3y
@user-sq6zm6wk3y 4 жыл бұрын
e.insert( END , digit )
@johankotze42
@johankotze42 4 жыл бұрын
@@user-sq6zm6wk3y Yes. Much better! :-)
@GabrielFragadaSilva
@GabrielFragadaSilva 3 ай бұрын
2:30 Just write "e.insert(END, number)"
@vik0_052
@vik0_052 3 жыл бұрын
what is the function of padx and pady? In the net it says "how many pixels to pad widget horizontally/vertically outside the widget's borders." I don't understand this statement. Could you please explain.
@Codemycom
@Codemycom 3 жыл бұрын
they deal with spacing around the widget. x is space to the left and right y is space above and below
@vik0_052
@vik0_052 3 жыл бұрын
@@Codemycom thank you 👍
@Codemycom
@Codemycom 3 жыл бұрын
@@vik0_052 sure thing
@DestoFlix
@DestoFlix 3 жыл бұрын
your simple but complicated. This is my first experience with python, the parts you assumed we know are the ones Im struggling with. I cant download or find Ming64 and took a while to understand where Kinter was or how to open it.
@DestoFlix
@DestoFlix 3 жыл бұрын
also using linux commands on a windows os confuses new guys even more, cause theyll try them on powershell
@Codemycom
@Codemycom 3 жыл бұрын
ming64 isn't a thing. You want the git bash terminal. git-scm.com or any terminal. Tkinter comes with Python, there's nothing to find or open.
@DestoFlix
@DestoFlix 3 жыл бұрын
@@Codemycom Took a while for me to notice that since I know nothing about Python. As for using other terminals I tried powershell, not sure if its my command or code thats not correct
@Codemycom
@Codemycom 3 жыл бұрын
@@DestoFlix No there is no powershell on linux. Just use the linux terminal. It comes with linux.
@DestoFlix
@DestoFlix 3 жыл бұрын
@@Codemycom perhaps something got lost in translation anyway the github app you recommended I download is working great and we are on the same page now. Much appreciated John
@khizaridrees1758
@khizaridrees1758 3 жыл бұрын
Need a Recommendation! : We should learn Kivy or Tkinter?
@Codemycom
@Codemycom 3 жыл бұрын
How can I possibly answer that? I have no idea what you need to do, what you want to use it for, the sort of apps you want to build, or your experience, skill, or aptitude.
@khizaridrees1758
@khizaridrees1758 3 жыл бұрын
@@Codemycom Just want to build ToDoList
@Codemycom
@Codemycom 3 жыл бұрын
@@khizaridrees1758 I'm building a todo list in tkinter right now...check the playlist.
@levinaa.377
@levinaa.377 2 жыл бұрын
what does e.get and e.grid mean?
@Codemycom
@Codemycom 2 жыл бұрын
Go back to the beginning of this playlist and start watching the videos if you want to learn those incredibly basic things.
@_Cartographer_
@_Cartographer_ 3 жыл бұрын
Why did we use lambda in the first place?
@REXanadu
@REXanadu 3 жыл бұрын
Using VS Code for tutorial. pylint keeps saying 'button_click is not callable.' I've looked online, but I haven't seen any solutions for how to fix this. What are your suggestions?
@Codemycom
@Codemycom 3 жыл бұрын
Don't use vscode lol I use sublime text and git-scm.com for the terminal.
@REXanadu
@REXanadu 3 жыл бұрын
Fixed it last night: it was an issue with how I accidentally factored one of the button names to be similar to a function used in program. That caused something with another function call to get stated as not callable. VS Code is fine; I just need to make sure I'm writing down everything as it appears in the video one-to-one. If this happens again with a video tutorial, I'll just make a github post with the finished script after each video for my own personal reference.
@Thememermanwhoisafan
@Thememermanwhoisafan 2 жыл бұрын
its telling me the colon after lambda for line 29 for you is a invalid syntax
@Codemycom
@Codemycom 2 жыл бұрын
Did you use a capital L in lambda? It needs to be lowercase
@3d_holyshit_tech591
@3d_holyshit_tech591 3 жыл бұрын
8:29 i got confused from the concept of how does the python calculator makes the + automaticly and what about more advanced programs im really deep into python i love how easy its to run a project :D not like javascript xD
@brodie2117
@brodie2117 4 жыл бұрын
Hello, I have run into an issue when it comes to displaying multiple numbers on the display. When I use the .get() function I either receive an error (listed below) or when I implemented a solution I thought would work [.get(0.0, tk.END)], I simply received nothing on my text box nor did I receive any errors. The previous tests you showed on the video (numbers being typed in the wrong order etc.) worked fine on my program. Assistance of any kind would be greatly appreciated. Thank you. --------------------------------------------------------- CODE def ButtonClick(number): current = InputBox.get() InputBox.delete(0.0, tk.END) InputBox.insert(0.0, str(current) + str(number)) ---------------------------------------------------------- ERROR current = InputBox.get() TypeError: get() missing 1 required positional argument: 'index1'
@Codemycom
@Codemycom 4 жыл бұрын
Seems like there's an error with your get() code...did you really name it InputBox?
@brodie2117
@brodie2117 4 жыл бұрын
@@Codemycom I figured as such but am unsure of what must be done to fix the error related to the .get() code. In terms of the InputBox, I named it that as I was planning to have another text box above it to show the equation the user inputted (EquationBox), once receiving the answer in the InputBox. Would this negatively affect my program or the process of creating it? Thank you for responding, it helps a great deal hearing from a professional.
@lzh00
@lzh00 4 жыл бұрын
I have a question, why all the numerical buttons used lambda function whereas others don't? When do I have to use lambda and when not?
@Codemycom
@Codemycom 4 жыл бұрын
because when you want to pass something to a function, you must use lambdas. The clear button doesn't pass anything to a function, so we don't have to use lambda.
@lzh00
@lzh00 4 жыл бұрын
@@Codemycom OK,really thanks and I pray for the US, keep strong💪💪
@Codemycom
@Codemycom 4 жыл бұрын
@@lzh00 Sure thing
@lzh00
@lzh00 4 жыл бұрын
@@Codemycom Can you help me show plots using a GUI? I use Seaborn and Matplotlib to show plots based on data, how can I have a button that when clicked shows a plot?
@Codemycom
@Codemycom 4 жыл бұрын
@@lzh00 already did: kzbin.info/www/bejne/bpbbc2mCrpihrpI
@friiiday_crown
@friiiday_crown 3 жыл бұрын
Cool and helpful videos! But why didn't you just use this?: def button_add(): current = e.get() e.delete(0, END) e.insert(0, str(current) + "+")
@Codemycom
@Codemycom 3 жыл бұрын
Always a million ways to do a thing
@skfungaming1308
@skfungaming1308 3 жыл бұрын
in line 29 e.insert(0, f_num + int(second_number)) f_num is not definited why i did it
@skfungaming1308
@skfungaming1308 3 жыл бұрын
please heeelp me
@Codemycom
@Codemycom 3 жыл бұрын
rewatch the entire video, you likely missed something
@skfungaming1308
@skfungaming1308 3 жыл бұрын
@@Codemycom I did, but I didn't find a mistake.
@xake995
@xake995 3 жыл бұрын
11:52
@leoronneland2633
@leoronneland2633 4 жыл бұрын
hey john, how shold i do if i want the calculator to be able to calculate the sum of three numbers, for examole 1 + 1 +1, thank you for this course btw :)
@Codemycom
@Codemycom 4 жыл бұрын
You'll have to play around with it and try some things. Work it out!
@leoronneland2633
@leoronneland2633 4 жыл бұрын
Codemy.com thank you so much
@Codemycom
@Codemycom 4 жыл бұрын
@@leoronneland2633 You're very welcome!
@SenthilManikandan
@SenthilManikandan 4 жыл бұрын
@Leo Ronneland To store e.get(), try using a global list to which you can append to . Then sum the last 2 elements on each button_add() call and export that to global variable to f_num, then this same f_num will be available when you call button_equals().
@user-ds9ey8pp5h
@user-ds9ey8pp5h 2 жыл бұрын
@Codemycom
@Codemycom 2 жыл бұрын
Thanks!
@kyawzinthant170
@kyawzinthant170 2 жыл бұрын
where can i get your code?
@Codemycom
@Codemycom 2 жыл бұрын
github.com/flatplanet/Intro-To-TKinter-KZbin-Course
@fedos
@fedos Жыл бұрын
Instead of getting the current value, deleting it, and then inserting it back with the concatenation, you can just use e.insert(END, number).
@ericgoovaerts2603
@ericgoovaerts2603 Жыл бұрын
👍
@juztinnandricepillo9824
@juztinnandricepillo9824 3 жыл бұрын
Hello, I followed the code but when I tried to run, this appeared: " line 21, in button_addition f_num = int(first_number) ValueError: invalid literal for int() with base 10: '' " whereas my code is: def button_addition(): first_number = e.get() global f_num f_num = int(first_number) e.delete(0, END) I don't understand why.. Please help
@user-zq1vg8xm1p
@user-zq1vg8xm1p 2 жыл бұрын
Look at @cookie 's comment. if it doesn't solve the problem, I recommend removing the bracket from the command=button_addition(), for example, butadd = Button(root, text="+", padx=39, pady=20, command=button_addition()) needs to be : butadd = Button(root, text="+", padx=39, pady=20, command=button_addition) if that doesn't work, put the 'eval' function before the variable in the int for example : def button_addition(): first_number = e.get() global f_num f_num = int(first_number) e.delete(0, END) needs to be : def button_addition(): first_number = e.get() global f_num f_num = int(eval(first_number)) e.delete(0, END) hope this helps :D
@mayurkalsekar524
@mayurkalsekar524 2 жыл бұрын
@@user-zq1vg8xm1p man you are briliant
@JC-qz4pd
@JC-qz4pd 4 жыл бұрын
when I use .int() it comes up with: ValueError: invalid literal for int() with base 10: ''. But whem i use .float() it comes up with: ValueError: could not convert string to float: ''
@Codemycom
@Codemycom 4 жыл бұрын
you're trying to pass a string to it...you can't do that. Letters can't be converted to numbers.
@JC-qz4pd
@JC-qz4pd 4 жыл бұрын
@@Codemycom ok, thank you
@infinitespace1982
@infinitespace1982 3 жыл бұрын
I remember when I did this programming, I couldn't multiply and that was because I incorrectly spelt 'multiplication' somewhere
@Codemycom
@Codemycom 3 жыл бұрын
fun
@muruganrg7020
@muruganrg7020 3 жыл бұрын
What is the mistake in the program it is not showing any error the calculator is opening it is accepting the values but it is not giving the answer I have added my code in the reply section.
@muruganrg7020
@muruganrg7020 3 жыл бұрын
from tkinter import* root=Tk() root.title("Simple Calculator") #to set the title of the app e=Entry(root,width=50,borderwidth=5) #for search box e.grid(row=0,column=0,columnspan=3,padx=10,pady=10) e.get() def button_click(number): current=e.get() e.delete(0,END) e.insert(END,number) def button_clear(): e.delete(0, END) def button_add(): first_number=e.get() global first_num first_num = int(first_number) e.delete(0,END) def button_equal(): second_number=e.get() e.delete(0,END) e.insert=(0, first_num+int(second_number)) #define buttons button_1=Button(root,text="1",padx=40,pady=20,command=lambda:button_click(1)) button_2=Button(root,text="2",padx=40,pady=20,command=lambda:button_click(2)) button_3=Button(root,text="3",padx=40,pady=20,command=lambda:button_click(3)) button_4=Button(root,text="4",padx=40,pady=20,command=lambda:button_click(4)) button_5=Button(root,text="5",padx=40,pady=20,command=lambda:button_click(5)) button_6=Button(root,text="6",padx=40,pady=20,command=lambda:button_click(6)) button_7=Button(root,text="7",padx=40,pady=20,command=lambda:button_click(7)) button_8=Button(root,text="8",padx=40,pady=20,command=lambda:button_click(8)) button_9=Button(root,text="9",padx=40,pady=20,command=lambda:button_click(9)) button_0=Button(root,text="0",padx=40,pady=20,command=lambda:button_click(0)) button_add=Button(root,text="+",padx=40,pady=20,command=button_add) button_equal=Button(root,text="=",padx=40,pady=20,command=button_equal) button_clear=Button(root,text="C",padx=40,pady=20,command=button_clear) #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_4.grid(row=2,column=0) button_5.grid(row=2,column=1) button_6.grid(row=2,column=2) button_7.grid(row=1,column=0) button_8.grid(row=1,column=1) button_9.grid(row=1,column=2) button_0.grid(row=4,column=0) button_add.grid(row=4,column=2) button_equal.grid(row=4,column=3) button_clear.grid(row=1,column=4) root.mainloop()
@ayushvarshney1925
@ayushvarshney1925 4 жыл бұрын
Hey I m getting an error can anyone help me out..! button_clear = Button(root, text= "clear", padx=79, pady=20, command =button_clear) UnboundLocalError : local variable 'button_clear' refrenced before assignment
@Codemycom
@Codemycom 4 жыл бұрын
you can put padx and pady there, you have to put them in button_clear.pack(), but also you are calling button_clear in your program before you create it.
@rakeshkundu
@rakeshkundu 3 жыл бұрын
invalid literal for int() with base 10: ''....... I'm getting this error. How can I fix this??
@Codemycom
@Codemycom 3 жыл бұрын
You likely have a typo
@rakeshkundu
@rakeshkundu 3 жыл бұрын
@@Codemycom I'm having another error. I'm getting invalid syntax for def button_clear(): e.delete(0, END)
@Codemycom
@Codemycom 3 жыл бұрын
@@rakeshkundu e.delete(0, END) that should be a zero not the letter O, right? If that's not the issue, try "end" instead of END
@dopegaming8334
@dopegaming8334 3 жыл бұрын
dose this works in pychram
@dopegaming8334
@dopegaming8334 3 жыл бұрын
Exception in Tkinter callback Traceback (most recent call last): File "C:\Users\Dell\AppData\Local\Programs\Python\Python38-32\lib\tkinter\__init__.py", line 1883, in __call__ return self.func(*args) File "C:/Users/Dell/PycharmProjects/Tk.py", line 20, in button_add f_num=int(first_number) ValueError: invalid literal for int() with base 10: ''
@Codemycom
@Codemycom 3 жыл бұрын
no idea...I would never use pycharm
@AnujKumar-xn5tg
@AnujKumar-xn5tg 3 жыл бұрын
Sir I have also made an Calculator .But can we send this app to others via link or an url??
@Codemycom
@Codemycom 3 жыл бұрын
Sure...you need to convert it into an exe file first...which can be tricky.
@AnujKumar-xn5tg
@AnujKumar-xn5tg 3 жыл бұрын
@@Codemycom I will try
@AnujKumar-xn5tg
@AnujKumar-xn5tg 3 жыл бұрын
@@Codemycom sir i have convert it into exe file now what is the next step ...
@Codemycom
@Codemycom 3 жыл бұрын
@@AnujKumar-xn5tg You need to upload it to a website where you can give the link out
@hushamqasim3833
@hushamqasim3833 4 ай бұрын
entr1.insert(END,number)
@Codemycom
@Codemycom 4 ай бұрын
yep
@amanullahakber5369
@amanullahakber5369 3 жыл бұрын
How we download this vedio code??
@Codemycom
@Codemycom 3 жыл бұрын
Link to my code is in the pinned comment. github.com/flatplanet/Intro-To-TKinter-KZbin-Course
@fonzyurriquia8640
@fonzyurriquia8640 3 жыл бұрын
The "END" word gives me error. What should i do?
@kshitij3826
@kshitij3826 3 жыл бұрын
Try and write it in small letters. Sorry for late reply
@faheemali5160
@faheemali5160 3 жыл бұрын
I have a syntax error when putting lambda,button_1=Button(root,text="9",padx=40,pady=30,command=Lambda: button_click(9)) Can u help me
@Codemycom
@Codemycom 3 жыл бұрын
The L in lambda needs to be lower case, not capitalized
@faheemali5160
@faheemali5160 3 жыл бұрын
@@Codemycom Thank u
@Codemycom
@Codemycom 3 жыл бұрын
@@faheemali5160 sure thing
@MrJzvoyeur
@MrJzvoyeur 4 жыл бұрын
def button_click(number): e.insert(END, number)
@Codemycom
@Codemycom 4 жыл бұрын
ok
@amanullahakber5369
@amanullahakber5369 3 жыл бұрын
Any video code??
@Codemycom
@Codemycom 3 жыл бұрын
Link to my code is in the pinned comment. github.com/flatplanet/Intro-To-TKinter-KZbin-Course
@learnprogramwithrksingh4605
@learnprogramwithrksingh4605 4 жыл бұрын
Error f_num is not define in the global scope python
@Codemycom
@Codemycom 4 жыл бұрын
make f_num global then
MEU IRMÃO FICOU FAMOSO
00:52
Matheus Kriwat
Рет қаралды 21 МЛН
Получилось у Вики?😂 #хабибка
00:14
ХАБИБ
Рет қаралды 2,8 МЛН
Just try to use a cool gadget 😍
00:33
123 GO! SHORTS
Рет қаралды 84 МЛН
Stupid Barry Find Mellstroy in Escape From Prison Challenge
00:29
Garri Creative
Рет қаралды 19 МЛН
Unlocking your CPU cores in Python (multiprocessing)
12:16
mCoding
Рет қаралды 293 М.
Python Calculator with GUI using Tkinter in Visual Studio Code
23:22
How ChatGPT Built My App in Minutes 🤯
8:28
Website Learners
Рет қаралды 2 МЛН
I use Drag and Drop to build modern Python Apps
14:08
Softlinks
Рет қаралды 46 М.
Build A Simple Calculator App - Python Tkinter GUI Tutorial #5
18:05
This Is Why Python Data Classes Are Awesome
22:19
ArjanCodes
Рет қаралды 792 М.
STOP Learning These Programming Languages (for Beginners)
5:25
Andy Sterkowitz
Рет қаралды 652 М.
This INCREDIBLE trick will speed up your data processes.
12:54
Rob Mulla
Рет қаралды 257 М.
Using tkinter with classes
28:23
Atlas
Рет қаралды 52 М.
MEU IRMÃO FICOU FAMOSO
00:52
Matheus Kriwat
Рет қаралды 21 МЛН