Math Calculator Buttons With eval() - Python Kivy GUI Tutorial #19

preview_player
Показать описание
In this video we'll finish our calculator's math buttons using the Python eval() function.

Eval() will take a string and break it apart and evaluate it, ie do the math.

So we don't have to write code for each of the buttons (add, subtract, multiply, divide), eval will take care of all of it for us.
Рекомендации по теме
Комментарии
Автор

▶️ Watch Entire Kivy Playlist ✅ Subscribe To My YouTube Channel:
▶️ See More At: ✅ Join My Facebook Group:
▶️ Get The Code

Codemycom
Автор

I look forward to taking lunch breaks just to watch your videos. I love all your teachings! Also, I completed my percentage button. Probably use some tweaking, but it works as is.

def percentage(self):

if self.answer == '0':
pass
else:
self.answer = self.answer / 100
self.ids.calc_input.text = str(self.answer)
self.answer = '0'

joephinazee
Автор

Hands Down the Best Tutorial Ever !! No perplexing, no confusions just a plain, easy and nice approach to teach the stuff !! Keep up the good work.👍👍👌👌😎😎

sparshbatta
Автор

Thanks for the lesson and mad props to all the calculator creators out there. It it is fun to see how easy one missed function can break/fix a whole lot of things.

gregnstuff
Автор

Good Kivy tutorial. Division needs some work. When the answer goes on forever past the decimal, eval() works, but in the calculator, what's displayed is just part of the answer, like the last three digits of for "5/6". If you print the answer it's right but it doesn't display right in the calculator. Solved by using the round() function built into Python.

unclebuddy
Автор

Funny thing in programming world is this surprised face when you don't expect something to work, or like in this case work so well xD

Thank you very much for presenting us these things in such simple manner, and i'm glad your dog is fine!

nejinii
Автор

Thank you very much. I've learned many things from your series...

miladsmaeeli
Автор

Percentage function with '+' and '-' operations. For example: 90 + 10% of 90 = 99. It can be modified further in similar way:
def percentage(self):
global result, result2
prior = self.ids.calc_input.text
if '+' in prior:
result = prior.split('+')
else:
result2 = prior.split('-')
if prior == '0':
pass
elif '-' in prior and len(result2) == 2:
result3 = float(result2[0]) - (float(result2[0]) / 100)*float(result2[-1])
self.ids.calc_input.text = str(round(result3, 3))
elif '+' in prior and len(result) == 2:
result4 = float(result[0]) + (float(result[0]) / 100)*float(result[-1])
self.ids.calc_input.text = str(round(result4, 3))

msvisoko
Автор

Another alternative for division:

if '/' in prior:
num_list = prior.split('/')
answer = 1

for number in num_list:
answer = int(num_list[0]) / int(num_list[1])


self.ids.calc_input.text = str(answer)

playerandroidtutoriais
Автор

Hi John, thanks for uploading these videos. I really learn a lot with them
I have a question: can you import "special" functions like sin, cos, exponential, etc and place them in the calculator?

franciscocardozo
Автор

Hi John

Love all the work you do. I'm an IT teacher and you're the #1 place I send my students to understand Python GUI programming.

Mate, I seem to get really weird values when I divide by 3. For example 10/3 will give 335, 7/3 = 335. 10/6 = 667. Any ideas what I've done wrong?

DamienMurtagh-Galea
Автор

6:20 i think it is supposed to mean modulo but im not sure
and also "//" is floor div

drcgaming
Автор

Me watching this video. Suddenly a load shedding occars . Wi-Fi turn off. I make the calculator without watching this video. Yay!

saadahmedkhan
Автор

I challenge all of you to code overflow error. The logic is pretty simple. If the answer is more than 12 digits, it will output an error, just like standard calculator. For example, = Error.

paulushimawan
Автор

I am getting below error message during execution with eval() function . May kindly please help fixing the issue.
AttributeError: 'super' object has no attribute '__getattr__'

abhishekranjan
Автор

Maybe you fix this in a later video, but a subtraction operator will simply be deleted from the text input if you press the +/- button. So "3*5-10" will become "3*510".

Do I have that right?

erindeerhart
Автор

I recently started learning Kivy and someone said that learning UI framework in python is just a waste of time. Is this true?

swastiksarkar
Автор

I've been watching your videos. And I seem to not be able to figure out how to clear the text input automatically after the answer has been displayed, when the user will enter another set of numbers, without pressing the C button.

christopherjonesramos
Автор

hello, I change the color's button in kivy file whit canvas, but I want to change the colour of button when pressing this, but I can't .
can you help me, thank you sir :)

elenaab
Автор

There is an error
Can you please try 6/9

yahyaa