▶️ Watch Entire Tkinter Playlist ✅ Subscribe To My RUclips 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 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
@@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))
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.
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.
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.
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
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
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).
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.
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 😆
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?
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
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,
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))
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)
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
@@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?
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)
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.
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
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)
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???
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 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 😎
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.
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
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.
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?
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 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.
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
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'
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))
@@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.
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.
@@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?
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.
@@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 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
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.
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?
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: ''
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?
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.
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.
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
@@donaldppaul3260 Oh, that's the end of the box. Each character in the entry box is numbered, and you want to delete everything in the box from the first character to the end character.
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
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
▶️ Watch Entire Tkinter Playlist ✅ Subscribe To My RUclips 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
What does END do
@@donaldppaul3260 What do you think? It ends a thing.
@@Codemycom pls explain why do you use a END in e.insert(END,number)
@@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
@@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))
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.
Thanks! Glad you like it!
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.
Glad you enjoyed it!
1:10 On the 13th line you could write 'END' insead of 0 and it'll be working.
nichego sebe
Yes, I was about to say the same thing. Much simpler way.
try with a capital letters,i tried and its work
Yes, I'm agree with you!
Genius. Just Genius
"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!
ha, glad you're enjoying it!
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.
Wow thanks! That's high praise! Glad you're enjoying them...
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
The best tkinter Tutorial in the youtube.
Thanks!
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.
Happy to hear it!
To how want's to learn python easy this good chanel لكل من يريد تعلم بايتون هذه القناة افضلل مكان للتعلم.
شكرا كثيرا thanks lot
Thanks!
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
Thanks, it worked.
Dude you are bloody brilliant. I will buy yours courses. Loving this!
Awesome, glad you like it!
I can't believe that I have 170 more amazing videos to watch!
Enjoy!
This channel is so underrated.
Thanks! Tell your friends!
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).
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.
U are the best programmer. that I saw
Thanks!
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
😆
I like your reaction when your code runs! lol
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?
Why we should use lambda to execute the command
Because that's the only way tkinter allows you to pass variables through your function from the button.
@@Codemycom It's not the only way, just a very common way. For example, you could also use functools.partial.
Best web series I am watching right now
Happy to hear it!
Gracias profe, saludos desde Bucaramanga-Colombia
Welcome
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
fun
You could've used the inbuilt string split method for adding numbers, btw thanks for the great tutorial series
Sure, there's always a hundred different ways you can do a thing
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,
Welcome!
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))
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)
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
Because pyCharm is garbage.
Hi, the videos are all good, thank you very much.
We may write
a=e.get()
e.insert(len(a),num)
sure
2:47
if you type
click the buttons like this
1,2,3,4,5,6...
you get the abacaba sequence!
VERY HELPFUL, IM JUST A 13-YEAR-OLD AND I LOVE IT, THANKS A LOT, @PRANAVA
AND DO YOU HAVE 1 TO 1 COURSES
Glad you liked it. I don't know what 1 to 1 courses are.
@@Codemycom one instructor , one student. Mo' Moneyy!
@@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?
@@Codemycom i didnt really understand the money part, sorry i thought thats how it worked, but anyways thanks for this amazing seeries tho
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)
cool
My first thought for doing the addition was to just turn this into a class :P
fun
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.
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
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. 😃
So helpful! Thank you!
Glad you liked it Angelaine!
Use: e.insert(END, str(number)) to append text in one command
sure
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)
There are always infinite ways to do a thing.
2:30 Just write "e.insert(END, number)"
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???
store result in a list and when u hit equal to then only process sum of all the element in the list
@@sarvdeepsangwan1207 okh thank u 👍
Sir, if we use this e.insert(END,number), then we can do it in just 1 line
yeah
thank you for this. helps a lot!
Glad to hear it!
insert all values as string and use eval function. it will be better
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?
Not sure what you mean
@@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 😎
@@Abhijeetetrx ah cool, glad you got it sorted out :-)
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
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.
That just slaps it on the end of the entry box. If there's another number there already it wont work
Hello , you're amazing , I'm sorry i have a problem , the global variable it doesn't work for me , what's the problem?
You used it incorrectly. What did you do differently from the video?
Thanks ..helpful
Glad to help
hey i was just wondering is there any way to have a backspace button, which only deletes the last digit??
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
You may write func like this
a=e.get()
e.delete(len(a)-1,END)
If I wanna write the number 123, to fix the adding problem, I used:
def buuton_click(number):
e.insert(END, number)
thank you!
can you know how can i create a calculator salary avarage with this?
use basic math
Instead of getting the current value, deleting it, and then inserting it back with the concatenation, you can just use e.insert(END, number).
👍
you can out the two numbers in a list and add them together
Sure
Need a Recommendation! : We should learn Kivy or Tkinter?
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.
@@Codemycom Just want to build ToDoList
@@khizaridrees1758 I'm building a todo list in tkinter right now...check the playlist.
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?
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'
Seems like there's an error with your get() code...did you really name it InputBox?
@@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.
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
what is the error telling you?
I am using Python version 3.9.0
and the error is
Invalid Literal for int() with base 10
did you use the letter 0 instead of the number 0 in your calculator label?
I used letter 0
@@ansh4786 It must be number 0...this is a calculator...it does math to numbers. integers.
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'
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()
@@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.
Thank you
Welcome!
Can't I just use e.insert(END, number) or is there a problem?
in line 29 e.insert(0, f_num + int(second_number))
f_num is not definited
why
i did it
please heeelp me
rewatch the entire video, you likely missed something
@@Codemycom I did, but I didn't find a mistake.
pretty coooooool
Thanks!
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?
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.
@@Codemycom OK,really thanks and I pray for the US, keep strong💪💪
@@lzh00 Sure thing
@@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?
@@lzh00 already did: ruclips.net/video/8exB6Ly3nx0/видео.html
In button_click I did:
e.insert( len( e.get() ) , digit )
to address that incorrect order.
e.insert( END , digit )
e.insert( END , digit )
@@彭随风 Yes. Much better! :-)
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.
also using linux commands on a windows os confuses new guys even more, cause theyll try them on powershell
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.
@@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
@@DestoFlix No there is no powershell on linux. Just use the linux terminal. It comes with linux.
@@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
5:00 why did he remove the brackets from in front of the function, don't we need them to call a function ?
Because the clear button calls a function that doesn't require a parameter. Therefore no lambda and no brackets are needed :)
it calls a void
great, thanks
Welcome :-)
Thanks bro🤗
sure thing
@@Codemycom bro one help: How to provide entry box for only getting integer input??
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) + "+")
Always a million ways to do a thing
obrigado pelos videos
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 .
Then you have a typo somewhere. Is lambda lowercase?
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.
root.quit() usually works. root.destroy() might do the trick
How do you do a while loop with the tkinter library
In the same way you do any while loop...it's python, it has nothing to do with tkinter.
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?
continue watching the videos
its telling me the colon after lambda for line 29 for you is a invalid syntax
Did you use a capital L in lambda? It needs to be lowercase
dose this works in pychram
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: ''
no idea...I would never use pycharm
Why did we use lambda in the first place?
I remember when I did this programming, I couldn't multiply and that was because I incorrectly spelt 'multiplication' somewhere
fun
what does e.get and e.grid mean?
Go back to the beginning of this playlist and start watching the videos if you want to learn those incredibly basic things.
Watch at x1.25. Enjoy!
lol
@@Codemycom Haha. You are brilliant. I was looking your videos right now !:)
@@imherovirat thanks
Sir while executing the stuff the system said that 'padx' is not defined. How should I fix that?
check your code for typos. It has to be exact
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?
Don't use vscode lol I use sublime text and git-scm.com for the terminal.
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.
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.
they deal with spacing around the widget. x is space to the left and right y is space above and below
@@Codemycom thank you 👍
@@vik0_052 sure thing
def button_click(number):
e.insert(END, number)
ok
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
11:52
Sir I have also made an Calculator .But can we send this app to others via link or an url??
Sure...you need to convert it into an exe file first...which can be tricky.
@@Codemycom I will try
@@Codemycom sir i have convert it into exe file
now what is the next step ...
@@AnujKumar-xn5tg You need to upload it to a website where you can give the link out
WHAT DOES END DO PLS HELP
End ends a thing
@@Codemycom pls explain e.delete(0,END) WHAT DOES THAT END
@@donaldppaul3260 Oh, that's the end of the box. Each character in the entry box is numbered, and you want to delete everything in the box from the first character to the end character.
@@Codemycom thank you for helping .that was a pain. I thought you would be harsh but you are a nice guy
great
Thanks!
def button_clear():
e.delete(0, END)
Dear Sir, I'm facing problem on these lines.
Hmmm try e.insert(0, END)
it says f_num not defined. Why?
nvm found my mistake
glad you found it
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
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
@@user-zq1vg8xm1p man you are briliant
invalid literal for int() with base 10: ''....... I'm getting this error. How can I fix this??
You likely have a typo
@@Codemycom I'm having another error. I'm getting invalid syntax for
def button_clear():
e.delete(0, END)
@@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
where can i get your code?
github.com/flatplanet/Intro-To-TKinter-RUclips-Course
'Lambda: ' doesn't work. Can I install that?
Yes it does work, you used a capital L instead of lowercase.
What do it's saying f_num is not defined in the global scope?
try making it global
@@Codemycom before the function I wrote f_num = 0 then it worked,what does this mean?
@@m.hassanakram6527 you have to assign something to a variable before you call the variable...
@@Codemycom thanku but how ur code worked without it😂
@@m.hassanakram6527 Then why didn't yours? You must have done something differently
The "END" word gives me error. What should i do?
Try and write it in small letters. Sorry for late reply
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
The L in lambda needs to be lower case, not capitalized
@@Codemycom Thank u
@@faheemali5160 sure thing
Kivy vs Tkinter ? with Reason.😊
Every tool is different, has different strengths and weaknesses depending on what you need to use it for.
@@Codemycom Thank you so much.❤
my microsoft VS says i got 200 problems...
how?
Who knows. I would never use that tool.
Error f_num is not define in the global scope python
make f_num global then