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

  Рет қаралды 170,823

Codemy.com

Codemy.com

Күн бұрын

Пікірлер
@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 3 жыл бұрын
@@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 2 жыл бұрын
@@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 4 жыл бұрын
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 4 жыл бұрын
Thanks! Glad you like it!
@ничегосебе-в1ъ
@ничегосебе-в1ъ 4 жыл бұрын
1:10 On the 13th line you could write 'END' insead of 0 and it'll be working.
@dinona247
@dinona247 4 жыл бұрын
nichego sebe
@kjn5991
@kjn5991 4 жыл бұрын
Yes, I was about to say the same thing. Much simpler way.
@noaharonoff
@noaharonoff 4 жыл бұрын
try with a capital letters,i tried and its work
@ozbekchawindows4236
@ozbekchawindows4236 4 жыл бұрын
Yes, I'm agree with you!
@NOAHBENJ
@NOAHBENJ 4 жыл бұрын
Genius. Just Genius
@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...
@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!
@aminmech
@aminmech Жыл бұрын
The best tkinter Tutorial in the youtube.
@Codemycom
@Codemycom Жыл бұрын
Thanks!
@mrunixman1579
@mrunixman1579 10 ай бұрын
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 10 ай бұрын
Happy to hear it!
@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
@اماديرأمان-ر9ك
@اماديرأمان-ر9ك 2 жыл бұрын
To how want's to learn python easy this good chanel لكل من يريد تعلم بايتون هذه القناة افضلل مكان للتعلم. شكرا كثيرا thanks lot
@Codemycom
@Codemycom 2 жыл бұрын
Thanks!
@mrawesome7739
@mrawesome7739 3 жыл бұрын
I can't believe that I have 170 more amazing videos to watch!
@Codemycom
@Codemycom 3 жыл бұрын
Enjoy!
@daveandpamwilkinson3883
@daveandpamwilkinson3883 5 жыл бұрын
Dude you are bloody brilliant. I will buy yours courses. Loving this!
@Codemycom
@Codemycom 5 жыл бұрын
Awesome, glad you like it!
@EpicBURN321
@EpicBURN321 5 жыл бұрын
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 5 жыл бұрын
Thanks, it worked.
@hossamketfi9892
@hossamketfi9892 2 жыл бұрын
This channel is so underrated.
@Codemycom
@Codemycom 2 жыл бұрын
Thanks! Tell your friends!
@user-hl6cq4jm3l
@user-hl6cq4jm3l 4 жыл бұрын
U are the best programmer. that I saw
@Codemycom
@Codemycom 4 жыл бұрын
Thanks!
@umpalumpa2883
@umpalumpa2883 4 жыл бұрын
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.
@_Cartographer_
@_Cartographer_ 4 жыл бұрын
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 4 жыл бұрын
Because the clear button calls a function that doesn't require a parameter. Therefore no lambda and no brackets are needed :)
@ничегосебе-в1ъ
@ничегосебе-в1ъ 3 жыл бұрын
it calls a void
@jorgebalagueraespinosa5936
@jorgebalagueraespinosa5936 Жыл бұрын
Gracias profe, saludos desde Bucaramanga-Colombia
@Codemycom
@Codemycom Жыл бұрын
Welcome
@數學只考6級分
@數學只考6級分 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 4 жыл бұрын
@@Codemycom It's not the only way, just a very common way. For example, you could also use functools.partial.
@SidneyJohnson-q7h
@SidneyJohnson-q7h Ай бұрын
Couldn´t you just save the input of everything, when they hit '=' the program splits the string in plus and then you just sum() the list. Or would´t it work?
@AhrenBaderJarvis
@AhrenBaderJarvis 4 жыл бұрын
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 4 жыл бұрын
cool
@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!
@pragunashok6008
@pragunashok6008 4 жыл бұрын
hey i was just wondering is there any way to have a backspace button, which only deletes the last digit??
@Codemycom
@Codemycom 4 жыл бұрын
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 4 жыл бұрын
You may write func like this a=e.get() e.delete(len(a)-1,END)
@kidredglow2060
@kidredglow2060 Жыл бұрын
2:47 if you type click the buttons like this 1,2,3,4,5,6... you get the abacaba sequence!
@luciferkhusrao
@luciferkhusrao 4 жыл бұрын
Sir, if we use this e.insert(END,number), then we can do it in just 1 line
@Codemycom
@Codemycom 4 жыл бұрын
yeah
@sasitobs4884
@sasitobs4884 Жыл бұрын
Best web series I am watching right now
@Codemycom
@Codemycom Жыл бұрын
Happy to hear it!
@marcmathieutrance6807
@marcmathieutrance6807 2 жыл бұрын
I like your reaction when your code runs! lol
@utsavpunia420
@utsavpunia420 4 жыл бұрын
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 3 жыл бұрын
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 👍
@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
@shamailanaimat7347
@shamailanaimat7347 4 жыл бұрын
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 4 жыл бұрын
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()
@ekirigwejames
@ekirigwejames 4 жыл бұрын
@@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.
@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 4 жыл бұрын
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
@IceTheCoder
@IceTheCoder Жыл бұрын
Can't I just use e.insert(END, number) or is there a problem?
@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
@parsabahrambeik4381
@parsabahrambeik4381 4 жыл бұрын
Hi, the videos are all good, thank you very much.
@MrGrey64
@MrGrey64 2 жыл бұрын
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 😆
@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?
@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.
@jelayneds2422
@jelayneds2422 5 жыл бұрын
So helpful! Thank you!
@Codemycom
@Codemycom 5 жыл бұрын
Glad you liked it Angelaine!
@hectorramsey318
@hectorramsey318 6 ай бұрын
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 6 ай бұрын
Because pyCharm is garbage.
@manikandannatarajan9665
@manikandannatarajan9665 4 жыл бұрын
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 4 жыл бұрын
Glad you liked it. I don't know what 1 to 1 courses are.
@varadvithalkj1716
@varadvithalkj1716 4 жыл бұрын
@@Codemycom one instructor , one student. Mo' Moneyy!
@Codemycom
@Codemycom 4 жыл бұрын
@@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 4 жыл бұрын
@@Codemycom i didnt really understand the money part, sorry i thought thats how it worked, but anyways thanks for this amazing seeries tho
@kindersmith8407
@kindersmith8407 4 жыл бұрын
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 4 жыл бұрын
root.quit() usually works. root.destroy() might do the trick
@johankotze42
@johankotze42 5 жыл бұрын
In button_click I did: e.insert( len( e.get() ) , digit ) to address that incorrect order.
@彭随风
@彭随风 5 жыл бұрын
e.insert( END , digit )
@彭随风
@彭随风 5 жыл бұрын
e.insert( END , digit )
@johankotze42
@johankotze42 5 жыл бұрын
@@彭随风 Yes. Much better! :-)
@vik0_052
@vik0_052 4 жыл бұрын
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 4 жыл бұрын
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 4 жыл бұрын
@@Codemycom thank you 👍
@Codemycom
@Codemycom 4 жыл бұрын
@@vik0_052 sure thing
@hardikpunj9321
@hardikpunj9321 4 жыл бұрын
We may write a=e.get() e.insert(len(a),num)
@Codemycom
@Codemycom 4 жыл бұрын
sure
@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. 😃
@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
@skfungaming1308
@skfungaming1308 4 жыл бұрын
in line 29 e.insert(0, f_num + int(second_number)) f_num is not definited why i did it
@skfungaming1308
@skfungaming1308 4 жыл бұрын
please heeelp me
@Codemycom
@Codemycom 4 жыл бұрын
rewatch the entire video, you likely missed something
@skfungaming1308
@skfungaming1308 4 жыл бұрын
@@Codemycom I did, but I didn't find a mistake.
@REXanadu
@REXanadu 4 жыл бұрын
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 4 жыл бұрын
Don't use vscode lol I use sublime text and git-scm.com for the terminal.
@REXanadu
@REXanadu 4 жыл бұрын
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.
@hagaibuachi2166
@hagaibuachi2166 3 жыл бұрын
thank you! can you know how can i create a calculator salary avarage with this?
@Codemycom
@Codemycom 3 жыл бұрын
use basic math
@kahoonalagona7123
@kahoonalagona7123 Жыл бұрын
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))
@ritusree05
@ritusree05 4 жыл бұрын
Sir while executing the stuff the system said that 'padx' is not defined. How should I fix that?
@Codemycom
@Codemycom 4 жыл бұрын
check your code for typos. It has to be exact
@rverm1000
@rverm1000 3 жыл бұрын
How do you do a while loop with the tkinter library
@Codemycom
@Codemycom 3 жыл бұрын
In the same way you do any while loop...it's python, it has nothing to do with tkinter.
@GabrielFragadaSilva
@GabrielFragadaSilva 10 ай бұрын
2:30 Just write "e.insert(END, number)"
@thehash8
@thehash8 3 жыл бұрын
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 3 жыл бұрын
continue watching the videos
@mbn-code
@mbn-code 4 жыл бұрын
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)
@lonxwolx
@lonxwolx 2 жыл бұрын
thank you for this. helps a lot!
@Codemycom
@Codemycom 2 жыл бұрын
Glad to hear it!
@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
@rodrigomsvlog
@rodrigomsvlog 4 жыл бұрын
If I wanna write the number 123, to fix the adding problem, I used: def buuton_click(number): e.insert(END, number)
@dylanl4802
@dylanl4802 2 жыл бұрын
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 2 жыл бұрын
That just slaps it on the end of the entry box. If there's another number there already it wont work
@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?
@raghavvasdeva2914
@raghavvasdeva2914 4 жыл бұрын
Can you explain why 15 become 151 & 1517 becomes 1517151 at 3:50sec of video
@Codemycom
@Codemycom 4 жыл бұрын
don't I explain it in the video a little further on?
@raghavvasdeva2914
@raghavvasdeva2914 4 жыл бұрын
I don't understand it. Kindly explain it again
@Codemycom
@Codemycom 4 жыл бұрын
@@raghavvasdeva2914 Sorry, rewatch the video.
@Cherry-z4f
@Cherry-z4f 10 ай бұрын
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 10 ай бұрын
You used it incorrectly. What did you do differently from the video?
@_Cartographer_
@_Cartographer_ 4 жыл бұрын
Why did we use lambda in the first place?
@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
@porcelainface7809
@porcelainface7809 4 жыл бұрын
My first thought for doing the addition was to just turn this into a class :P
@Codemycom
@Codemycom 4 жыл бұрын
fun
@khizaridrees1758
@khizaridrees1758 4 жыл бұрын
Need a Recommendation! : We should learn Kivy or Tkinter?
@Codemycom
@Codemycom 4 жыл бұрын
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 4 жыл бұрын
@@Codemycom Just want to build ToDoList
@Codemycom
@Codemycom 4 жыл бұрын
@@khizaridrees1758 I'm building a todo list in tkinter right now...check the playlist.
@ansh4786
@ansh4786 3 жыл бұрын
Error is showing in line f_num = int(first_number) What i wrote def button_add(): first_number=e.get() f_num=int(first_number) e.delete(0,END) What can be my mistake, please tell
@Codemycom
@Codemycom 3 жыл бұрын
what is the error telling you?
@ansh4786
@ansh4786 3 жыл бұрын
I am using Python version 3.9.0 and the error is Invalid Literal for int() with base 10
@Codemycom
@Codemycom 3 жыл бұрын
did you use the letter 0 instead of the number 0 in your calculator label?
@ansh4786
@ansh4786 3 жыл бұрын
I used letter 0
@Codemycom
@Codemycom 3 жыл бұрын
@@ansh4786 It must be number 0...this is a calculator...it does math to numbers. integers.
@sugarcurls4550
@sugarcurls4550 11 күн бұрын
You're Epiccc!!!
@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
@m.hassanakram6527
@m.hassanakram6527 4 жыл бұрын
What do it's saying f_num is not defined in the global scope?
@Codemycom
@Codemycom 4 жыл бұрын
try making it global
@m.hassanakram6527
@m.hassanakram6527 4 жыл бұрын
@@Codemycom before the function I wrote f_num = 0 then it worked,what does this mean?
@Codemycom
@Codemycom 4 жыл бұрын
@@m.hassanakram6527 you have to assign something to a variable before you call the variable...
@m.hassanakram6527
@m.hassanakram6527 4 жыл бұрын
@@Codemycom thanku but how ur code worked without it😂
@Codemycom
@Codemycom 4 жыл бұрын
@@m.hassanakram6527 Then why didn't yours? You must have done something differently
@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 3 жыл бұрын
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 3 жыл бұрын
@@user-zq1vg8xm1p man you are briliant
@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.
@faheemali5160
@faheemali5160 4 жыл бұрын
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 4 жыл бұрын
The L in lambda needs to be lower case, not capitalized
@faheemali5160
@faheemali5160 4 жыл бұрын
@@Codemycom Thank u
@Codemycom
@Codemycom 4 жыл бұрын
@@faheemali5160 sure thing
@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().
@johnpro2847
@johnpro2847 5 жыл бұрын
Thanks ..helpful
@Codemycom
@Codemycom 5 жыл бұрын
Glad to help
@AnujKumar-xn5tg
@AnujKumar-xn5tg 4 жыл бұрын
Sir I have also made an Calculator .But can we send this app to others via link or an url??
@Codemycom
@Codemycom 4 жыл бұрын
Sure...you need to convert it into an exe file first...which can be tricky.
@AnujKumar-xn5tg
@AnujKumar-xn5tg 4 жыл бұрын
@@Codemycom I will try
@AnujKumar-xn5tg
@AnujKumar-xn5tg 4 жыл бұрын
@@Codemycom sir i have convert it into exe file now what is the next step ...
@Codemycom
@Codemycom 4 жыл бұрын
@@AnujKumar-xn5tg You need to upload it to a website where you can give the link out
@fedos
@fedos 2 жыл бұрын
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 Жыл бұрын
👍
@entertainmentdevashishroy2760
@entertainmentdevashishroy2760 4 жыл бұрын
insert all values as string and use eval function. it will be better
@dopegaming8334
@dopegaming8334 4 жыл бұрын
dose this works in pychram
@dopegaming8334
@dopegaming8334 4 жыл бұрын
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 4 жыл бұрын
no idea...I would never use pycharm
@DestoFlix
@DestoFlix 4 жыл бұрын
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 4 жыл бұрын
also using linux commands on a windows os confuses new guys even more, cause theyll try them on powershell
@Codemycom
@Codemycom 4 жыл бұрын
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 4 жыл бұрын
@@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 4 жыл бұрын
@@DestoFlix No there is no powershell on linux. Just use the linux terminal. It comes with linux.
@DestoFlix
@DestoFlix 4 жыл бұрын
@@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
@moosman3527
@moosman3527 3 жыл бұрын
you can out the two numbers in a list and add them together
@Codemycom
@Codemycom 3 жыл бұрын
Sure
@kyawzinthant170
@kyawzinthant170 3 жыл бұрын
where can i get your code?
@Codemycom
@Codemycom 3 жыл бұрын
github.com/flatplanet/Intro-To-TKinter-KZbin-Course
@fonzyurriquia8640
@fonzyurriquia8640 4 жыл бұрын
The "END" word gives me error. What should i do?
@kshitij3826
@kshitij3826 4 жыл бұрын
Try and write it in small letters. Sorry for late reply
@marthadeboer4470
@marthadeboer4470 2 жыл бұрын
'Lambda: ' doesn't work. Can I install that?
@Codemycom
@Codemycom 2 жыл бұрын
Yes it does work, you used a capital L instead of lowercase.
@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()
@learnprogramwithrksingh4605
@learnprogramwithrksingh4605 4 жыл бұрын
Error f_num is not define in the global scope python
@Codemycom
@Codemycom 4 жыл бұрын
make f_num global then
@themeow6190
@themeow6190 3 жыл бұрын
my microsoft VS says i got 200 problems... how?
@Codemycom
@Codemycom 3 жыл бұрын
Who knows. I would never use that tool.
@themeow6190
@themeow6190 3 жыл бұрын
it says f_num not defined. Why? nvm found my mistake
@Codemycom
@Codemycom 3 жыл бұрын
glad you found it
@adiidan58
@adiidan58 4 ай бұрын
Use: e.insert(END, str(number)) to append text in one command
@Codemycom
@Codemycom 4 ай бұрын
sure
@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
@kshitij3826
@kshitij3826 4 жыл бұрын
When I try to run it it gives me "TypeError: 'Button' object is not callable " this error. I searched it on stackoverflow and it is not there too. Can anyone help me?
@parth2teja
@parth2teja 4 жыл бұрын
cross check the code above the # Define Buttons code (all the def and e.grid, etc.) and use proper brackets. It also happened with me and I got it fixed by this.
@kshitij3826
@kshitij3826 4 жыл бұрын
@@parth2teja thank you it worked!! : )
@parth2teja
@parth2teja 4 жыл бұрын
@@kshitij3826 It was the first time I helped someone ;) .
@praveenm9102
@praveenm9102 3 жыл бұрын
43 is showing name error name button is not defined
@Codemycom
@Codemycom 3 жыл бұрын
did you define the button?
@praveenm9102
@praveenm9102 3 жыл бұрын
@@Codemycom yes
@rushey_1771
@rushey_1771 5 жыл бұрын
Thanks bro🤗
@Codemycom
@Codemycom 5 жыл бұрын
sure thing
@rushey_1771
@rushey_1771 5 жыл бұрын
@@Codemycom bro one help: How to provide entry box for only getting integer input??
@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.
@monwan
@monwan 3 жыл бұрын
great, thanks
@Codemycom
@Codemycom 3 жыл бұрын
Welcome :-)
@khizaridrees1758
@khizaridrees1758 4 жыл бұрын
def button_clear(): e.delete(0, END) Dear Sir, I'm facing problem on these lines.
@hiwab41
@hiwab41 3 жыл бұрын
Hmmm try e.insert(0, END)
@xake995
@xake995 4 жыл бұрын
11:52
@alejandronavarro9835
@alejandronavarro9835 4 жыл бұрын
Bro, I have to do a calculator with cumulative operations enter by keyboard but when clicking in +, -, *, / the numbers are clear up but the are store for the operations. Example: 2+4+9-3=12 Could you help me please, I need it for 27 please bro ;)
@Codemycom
@Codemycom 4 жыл бұрын
Don't my videos show you how to do that?
@alejandronavarro9835
@alejandronavarro9835 4 жыл бұрын
@@Codemycom Yes yes, but if I enter with keyboard it works? Thanks being so fast :)
@Codemycom
@Codemycom 4 жыл бұрын
@@alejandronavarro9835 Sorry, I don't understand what you're saying. Enter what with keyboard?
@friiiday_crown
@friiiday_crown 4 жыл бұрын
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 4 жыл бұрын
Always a million ways to do a thing
@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.
Build A Simple Calculator App - Python Tkinter GUI Tutorial #5
18:05
人是不能做到吗?#火影忍者 #家人  #佐助
00:20
火影忍者一家
Рет қаралды 20 МЛН
Une nouvelle voiture pour Noël 🥹
00:28
Nicocapone
Рет қаралды 9 МЛН
How to treat Acne💉
00:31
ISSEI / いっせい
Рет қаралды 108 МЛН
СИНИЙ ИНЕЙ УЖЕ ВЫШЕЛ!❄️
01:01
DO$HIK
Рет қаралды 3,3 МЛН
Using tkinter with classes
28:23
Atlas
Рет қаралды 74 М.
Tkinter Course - Create Graphic User Interfaces in Python Tutorial
5:37:31
freeCodeCamp.org
Рет қаралды 3,4 МЛН
The ultimate introduction to modern GUIs in Python [ with tkinter ]
18:23:19
Python App Development: Build Modern GUIs in 7 Hours (Beginners Course)
6:42:29
Open Files Dialog Box - Python Tkinter GUI Tutorial #15
12:34
Codemy.com
Рет қаралды 195 М.
Radio Buttons with TKinter - Python Tkinter GUI Tutorial #12
17:44
Treeview - Python Tkinter GUI Tutorial #116
20:21
Codemy.com
Рет қаралды 142 М.
人是不能做到吗?#火影忍者 #家人  #佐助
00:20
火影忍者一家
Рет қаралды 20 МЛН