Python calculator app 🖩

  Рет қаралды 66,334

Bro Code

Bro Code

3 жыл бұрын

python calculator program project tutorial example explained
#python #calculator #program
****************************************************************
Python Calculator
****************************************************************
from tkinter import *
def button_press(num):
global equation_text
equation_text = equation_text + str(num)
equation_label.set(equation_text)
def equals():
global equation_text
try:
total = str(eval(equation_text))
equation_label.set(total)
equation_text = total
except SyntaxError:
equation_label.set("syntax error")
equation_text = ""
except ZeroDivisionError:
equation_label.set("arithmetic error")
equation_text = ""
def clear():
global equation_text
equation_label.set("")
equation_text = ""
window = Tk()
window.title("Calculator program")
window.geometry("500x500")
equation_text = ""
equation_label = StringVar()
label = Label(window, textvariable=equation_label, font=('consolas',20), bg="white", width=24, height=2)
label.pack()
frame = Frame(window)
frame.pack()
button1 = Button(frame, text=1, height=4, width=9, font=35,
command=lambda: button_press(1))
button1.grid(row=0, column=0)
button2 = Button(frame, text=2, height=4, width=9, font=35,
command=lambda: button_press(2))
button2.grid(row=0, column=1)
button3 = Button(frame, text=3, height=4, width=9, font=35,
command=lambda: button_press(3))
button3.grid(row=0, column=2)
button4 = Button(frame, text=4, height=4, width=9, font=35,
command=lambda: button_press(4))
button4.grid(row=1, column=0)
button5 = Button(frame, text=5, height=4, width=9, font=35,
command=lambda: button_press(5))
button5.grid(row=1, column=1)
button6 = Button(frame, text=6, height=4, width=9, font=35,
command=lambda: button_press(6))
button6.grid(row=1, column=2)
button7 = Button(frame, text=7, height=4, width=9, font=35,
command=lambda: button_press(7))
button7.grid(row=2, column=0)
button8 = Button(frame, text=8, height=4, width=9, font=35,
command=lambda: button_press(8))
button8.grid(row=2, column=1)
button9 = Button(frame, text=9, height=4, width=9, font=35,
command=lambda: button_press(9))
button9.grid(row=2, column=2)
button0 = Button(frame, text=0, height=4, width=9, font=35,
command=lambda: button_press(0))
button0.grid(row=3, column=0)
plus = Button(frame, text='+', height=4, width=9, font=35,
command=lambda: button_press('+'))
plus.grid(row=0, column=3)
minus = Button(frame, text='-', height=4, width=9, font=35,
command=lambda: button_press('-'))
minus.grid(row=1, column=3)
multiply = Button(frame, text='*', height=4, width=9, font=35,
command=lambda: button_press('*'))
multiply.grid(row=2, column=3)
divide = Button(frame, text='/', height=4, width=9, font=35,
command=lambda: button_press('/'))
divide.grid(row=3, column=3)
equal = Button(frame, text='=', height=4, width=9, font=35,
command=equals)
equal.grid(row=3, column=2)
decimal = Button(frame, text='.', height=4, width=9, font=35,
command=lambda: button_press('.'))
decimal.grid(row=3, column=1)
clear = Button(window, text='clear', height=4, width=12, font=35,
command=clear)
clear.pack()
window.mainloop()
****************************************************************
Bro Code merch store 👟 :
===========================================================
teespring.com/stores/bro-code-5
===========================================================
music credits 🎼 :
===========================================================
Up In My Jam (All Of A Sudden) by - Kubbi / kubbi
Creative Commons - Attribution-ShareAlike 3.0 Unported- CC BY-SA 3.0
Free Download / Stream: bit.ly/2JnDfCE
Music promoted by Audio Library • Up In My Jam (All Of A...
===========================================================

Пікірлер: 103
@BroCodez
@BroCodez 3 жыл бұрын
# **************************************************************** # Python Calculator # **************************************************************** from tkinter import * def button_press(num): global equation_text equation_text = equation_text + str(num) equation_label.set(equation_text) def equals(): global equation_text try: total = str(eval(equation_text)) equation_label.set(total) equation_text = total except SyntaxError: equation_label.set("syntax error") equation_text = "" except ZeroDivisionError: equation_label.set("arithmetic error") equation_text = "" def clear(): global equation_text equation_label.set("") equation_text = "" window = Tk() window.title("Calculator program") window.geometry("500x500") equation_text = "" equation_label = StringVar() label = Label(window, textvariable=equation_label, font=('consolas',20), bg="white", width=24, height=2) label.pack() frame = Frame(window) frame.pack() button1 = Button(frame, text=1, height=4, width=9, font=35, command=lambda: button_press(1)) button1.grid(row=0, column=0) button2 = Button(frame, text=2, height=4, width=9, font=35, command=lambda: button_press(2)) button2.grid(row=0, column=1) button3 = Button(frame, text=3, height=4, width=9, font=35, command=lambda: button_press(3)) button3.grid(row=0, column=2) button4 = Button(frame, text=4, height=4, width=9, font=35, command=lambda: button_press(4)) button4.grid(row=1, column=0) button5 = Button(frame, text=5, height=4, width=9, font=35, command=lambda: button_press(5)) button5.grid(row=1, column=1) button6 = Button(frame, text=6, height=4, width=9, font=35, command=lambda: button_press(6)) button6.grid(row=1, column=2) button7 = Button(frame, text=7, height=4, width=9, font=35, command=lambda: button_press(7)) button7.grid(row=2, column=0) button8 = Button(frame, text=8, height=4, width=9, font=35, command=lambda: button_press(8)) button8.grid(row=2, column=1) button9 = Button(frame, text=9, height=4, width=9, font=35, command=lambda: button_press(9)) button9.grid(row=2, column=2) button0 = Button(frame, text=0, height=4, width=9, font=35, command=lambda: button_press(0)) button0.grid(row=3, column=0) plus = Button(frame, text='+', height=4, width=9, font=35, command=lambda: button_press('+')) plus.grid(row=0, column=3) minus = Button(frame, text='-', height=4, width=9, font=35, command=lambda: button_press('-')) minus.grid(row=1, column=3) multiply = Button(frame, text='*', height=4, width=9, font=35, command=lambda: button_press('*')) multiply.grid(row=2, column=3) divide = Button(frame, text='/', height=4, width=9, font=35, command=lambda: button_press('/')) divide.grid(row=3, column=3) equal = Button(frame, text='=', height=4, width=9, font=35, command=equals) equal.grid(row=3, column=2) decimal = Button(frame, text='.', height=4, width=9, font=35, command=lambda: button_press('.')) decimal.grid(row=3, column=1) clear = Button(window, text='clear', height=4, width=12, font=35, command=clear) clear.pack() window.mainloop()
@rorornk0758
@rorornk0758 2 жыл бұрын
Hi
@numerousoriabure459
@numerousoriabure459 Жыл бұрын
Arigatou boss 。⁠◕⁠‿⁠◕⁠。
@tritontig3r
@tritontig3r 10 ай бұрын
Heard of Github ?
@blazer125
@blazer125 2 жыл бұрын
At first I was like "Could you go a little more in-depth with explaining the code?" But. That's when I realized I need to go on my own for deeper explanations. It makes it so much easier and satisfying to get yourself unstuck. Great Lesson Bro!
@adityanaik099
@adityanaik099 2 жыл бұрын
Made a simple calculator :) # Calculator program # In python #----------------------------- def addition(x,y): output1 = (x + y) return output1 #----------------------------- def subtraction(x,y): output2 = (x - y) return output2 #----------------------------- def multiplication(x,y): output3 = (x * y) return output3 #----------------------------- def division(x,y): output = (x / y) return output #----------------------------- def square(z): output4 = (z * z) return output4 #----------------------------- def cube(z): output5 = (z * z * z) return output5 #----------------------------- def factorial_pos(z): output6 = 1 for i in range(z,1,-1): output6 = (output6 * i) return output6 #----------------------------- def factorial_neg(z): output7 = -1 for i in range(z,-1): output7 = (output7 * i) return output7 #----------------------------- def exp_pos(b,p): output8 = 1 for i in range(p): output8 = (output8 * b) return output8 #----------------------------- def exp_neg(b,p): output9 = -1 for i in range(p): output9 = (output9 * b) return output9 #----------------------------- def mtp_tables_ps(x,y): print(" Result: ") for i in range(1,y+1): print(f"{x} x {i} = {x*i}") else: print(f''' These are the multiplication tables of {x} with-in the range of {y}''') #----------------------------- def mtp_tables_ng(x,y): print(" Result: ") for i in range(-1,(y-1),-1): print(f"{x} x {i} = {x*i}") else: print(f''' These are the multiplication tables of {x} with-in the range of {y}''') #----------------------------- def operator(c): if(c == ('+')): try: x = float(input("Enter 1st number : ")) y = float(input("Enter 2nd number : ")) except ValueError: print("You can only enter integers.Try to run again!") else: print("Result:") print(addition(x,y)) elif(c == ('-')): try: x = float(input("Enter 1st number : ")) y = float(input("Enter 2nd number : ")) except ValueError: print("You can only enter integers.Try to run again!") else: print("Result:") print(subtraction(x,y)) elif(c == ('*')): try: x = float(input("Enter 1st number : ")) y = float(input("Enter 2nd number : ")) except ValueError: print("You can only enter integers.Try to run again!") else: print("Result:") print(multiplication(x,y)) elif(c == ('/')): try: x = float(input("Enter 1st number : ")) y = float(input("Enter 2nd number : ")) division(x,y) except ValueError: print("You can only enter integers.Try to run again!") except ZeroDivisionError: print("You cant divide by 0.Try to run again!") else: print("Result:") print(division(x,y)) elif(c == ("**")): try: z = float(input("Enter the number to sqaure it : ")) except ValueError: print("You can only enter integers.Try to run again!") else: print("Result:") print(square(z)) elif(c == ("***")): try: z = float(input("Enter the number to cube it : ")) except ValueError: print("You can only enter integers.Try to run again!") else: print("Result:") print(cube(z)) elif(c == ('!')): try: z = int(input("Enter the number to calculate its factorial : ")) if(z > 0): print("Result:") print(factorial_pos(z)) elif(z < 0): print("Result:") print(factorial_neg(z)) else: if(z == 0): print("Result:") print(z*0) else: pass except ValueError: print("You can only enter Integers.Try to run again!") elif(c == ('exp')): try: b = int(input("Enter the base number : ")) p = int(input("Enter the power number : ")) if(p < 0): print("You cant enter negative integers as Power.Try to run again!") elif(b > 0): print("Result:") print(exp_pos(b,p)) elif(b < 0): print("Result:") print(exp_neg(b,p)) elif(b == 0): print("Result:") print(b*0) else: pass except ValueError: print("You can only enter Integers.Try to run again!") elif(c == "mtp"): try: x = int(input("Enter the number for its multiplication tables : ")) y = int(input("Enter the range for the tables : ")) if(y > 0): mtp_tables_ps(x,y) elif(y < 0): mtp_tables_ng(x,y) else: print("Result:") print(x*y) except ValueError: print("You can only enter Integers.Try to run again!") else: print("Invalid operator!") #----------------------------- def new_program(c): c = input('''Enter an operator sign: ('+' , '-' , '*' , '/' , '**' , '***' , '!' , 'exp' , 'mtp') : ''') operator(c) #----------------------------- c = input('''Enter an operator sign: ('+' , '-' , '*' , '/' , '**' , '***' , '!' , 'exp' , 'mtp') : ''') operator(c) print() ctn = input('''Do you want to continue your calculation? Enter 'y' for Yes / 'n' for No. : ''') ctn_cmd = ['y','Y','n','N'] while(ctn == 'y' or ctn == 'Y'): print() new_program(c) print() ctn = input('''Do you want to continue your calculation? Enter 'y' for Yes / 'n' for No. : ''') if(ctn == 'n' or ctn == 'N'): print() print("Thank you for using the calculator. ") else: if(ctn not in ctn_cmd): print("Invalid command!Try to run again.") else: pass #----------------------------- # Code finished successfully
@juankorsia7909
@juankorsia7909 2 жыл бұрын
From deep of my heart. Thanks very much!!!
@user-sj2mj5qw3o
@user-sj2mj5qw3o 9 ай бұрын
thanks for the short and understandable tutorial
@tread2114
@tread2114 Жыл бұрын
Great video!
@sebastiandworczyk4618
@sebastiandworczyk4618 Жыл бұрын
Love the channel !
@baahubaliankit5596
@baahubaliankit5596 2 жыл бұрын
i really love the way that you tech bro i am grateful to be taught by u thank you
@mrbrain8385
@mrbrain8385 3 жыл бұрын
I really love your channel
@soulninjadev
@soulninjadev 3 жыл бұрын
noice vids dude!
@JamilKhan-qk1no
@JamilKhan-qk1no 2 жыл бұрын
This is an awesome tutorial bro! Keep it up. As a python learner I want to know how can I bind keyboard keys in this calculator.
@2ncielkrommalzeme210
@2ncielkrommalzeme210 Жыл бұрын
your try is good thanks
@harshbhadrawale2645
@harshbhadrawale2645 24 күн бұрын
thanks this tutorial was really helpfull
@theaddictor
@theaddictor 3 жыл бұрын
Thank you so much...it really helps me❤️
@damdom2007
@damdom2007 Жыл бұрын
thank you so much.. i had so much fun creating this project. liked and subscribed
@kapibara2440
@kapibara2440 5 ай бұрын
Amazing content Bro ❤
@im_a-walking_shitpost_machine
@im_a-walking_shitpost_machine Жыл бұрын
wow this is very helpful
@mustefaosman2893
@mustefaosman2893 5 ай бұрын
This really helped me, thanks bro
@hamzaammar4356
@hamzaammar4356 2 жыл бұрын
YOUR A LIFE SAVER
@blexbottt5119
@blexbottt5119 Жыл бұрын
Thank you so much bro!
@prabhathprabhath9177
@prabhathprabhath9177 3 ай бұрын
excelent bro..
@user-og3qh7xl8t
@user-og3qh7xl8t 8 ай бұрын
Thanks so much. I love this video
@oguzhantopaloglu9442
@oguzhantopaloglu9442 3 жыл бұрын
amazing
@shahzodsayfiddinov9510
@shahzodsayfiddinov9510 3 жыл бұрын
Thank you Bro!
@tmahad5447
@tmahad5447 Жыл бұрын
This video is helpful
@jhassee
@jhassee Жыл бұрын
commented and subscribed
@jaumemoreno2544
@jaumemoreno2544 2 жыл бұрын
Thank you from Spain
@coachbussimulator6831
@coachbussimulator6831 2 жыл бұрын
cool
@user-nt6gm5ge4t
@user-nt6gm5ge4t 2 жыл бұрын
love u king
@IMCYT
@IMCYT 2 жыл бұрын
I tried to code it myself before this, it went well but I made each function for each number, i probably need to learn more lol
@omarsucess
@omarsucess 8 ай бұрын
thanks so much
@akazagiyu
@akazagiyu 9 ай бұрын
Thankk you bro codee this is a good tkinter study
@WorldPacMan256Village
@WorldPacMan256Village 11 ай бұрын
OMG. Thanks❤❤❤
@arshiaa104
@arshiaa104 Жыл бұрын
tnx ❤❤❤❤
@oukirimiryad9585
@oukirimiryad9585 5 ай бұрын
thx bro
@Skelton24
@Skelton24 10 ай бұрын
Your the best dude🗿
@milky_edge1123
@milky_edge1123 Жыл бұрын
I am not gonna lie it is criminal to be this good at code
@souravsarkar6107
@souravsarkar6107 2 жыл бұрын
thanks
@NOTHING-en2ue
@NOTHING-en2ue Жыл бұрын
thank you sosososososoososososooooooooooooooooo much ❤
@angelahamidi4274
@angelahamidi4274 2 жыл бұрын
i love you bro
@bahaaahmed7056
@bahaaahmed7056 9 ай бұрын
thank u man
@aveeopppp1428
@aveeopppp1428 2 ай бұрын
i have power "to 2k to 2.1k" but i will give a prayer to yt algo
@dollykahar7837
@dollykahar7837 Жыл бұрын
Nice
@rajeevkumarjha8748
@rajeevkumarjha8748 Күн бұрын
he is on fire mode
@adamritchey3327
@adamritchey3327 Жыл бұрын
How would you fix the decimal + decimal issue where it gives you a run on number?
@w.p.c.7113
@w.p.c.7113 2 жыл бұрын
I would like to thank you for your fantastic tutorials, they are helpful, and I have a question how can use both keyboard and button to enter numbers in calculator program.
@abdallahbadr4335
@abdallahbadr4335 Жыл бұрын
so late but I think you should watch the keyboard events lesson on his channel. you will use the window.bind method I think
@udayvadecha2973
@udayvadecha2973 5 ай бұрын
@@abdallahbadr4335 I'm using window.bind function to call button_press(), but button_press function is getting executed automatically when running a code. please help. window.bind("", button_press("+"))
@jhinc7
@jhinc7 Жыл бұрын
mewo (just to doing what u said at the finish)
@EmanQalqon
@EmanQalqon Ай бұрын
good
@davidhirschhorn2960
@davidhirschhorn2960 Ай бұрын
Thanks. equation_label = StringVar() is not trivial - I had to look up more info. Is it automatically global, and in scope in all of the defined functions?
@Joseph20003
@Joseph20003 2 ай бұрын
Hi bro, I'm a beginner in Python. First of all, thank you for the video, it helped me a lot. Second, I have a question: (I apologize if I make any grammatical mistakes, as I'm not very good at writing English) Why did you use lambda functions for the buttons? When I remove the lambda functions from the buttons and run the program, all the numbers and symbols are displayed without pressing any buttons. What is the reason for this?
@idevsl8245
@idevsl8245 3 жыл бұрын
Bro Code, i wanna ask you, maybe it's stupid question, sorry for that. We have class and examples of class - objects. Question: how to make some visible object with its own properties and methods? For example i'd like to know how to create a text frame, wich i could paint on a form, i mean it's like in programm Photoshop or Adobe InDesign.
@davidcalebpaterson7101
@davidcalebpaterson7101 2 жыл бұрын
In the video that he made the several balls animation he did something similar only that he created them as labels like oval widgets but can also be done in a different way by creating potoimage variables, and then passing them as arguments after self. it's actually easier since you will need less parameters. For example you won't need to pass fill color.
@BigMarc-wn1kw
@BigMarc-wn1kw Жыл бұрын
My buttons are not working even though I checked the video a lot of times and they won’t do anything when pressed. Do you know how to fix this?
@princesimfukwe9158
@princesimfukwe9158 Жыл бұрын
Same here
@jaspreetsingh7441
@jaspreetsingh7441 Жыл бұрын
same
@derpfisti2457
@derpfisti2457 Жыл бұрын
step 3 = done step 1 = done 👍 step 2 = done 🗯 great work again Bro!
@rishisid
@rishisid 3 жыл бұрын
More JavaFX Videos Please
@BroCodez
@BroCodez 3 жыл бұрын
I understand, but I don't want my Python people to feel left out
@guljain1684
@guljain1684 Жыл бұрын
can someone please tell how to add operators like log, sin, cos, tan from math library in this?
@coopahtroopah69
@coopahtroopah69 6 ай бұрын
import math and make seperate functions with a matrix of quasi polar tensors summating at the origin of the orthogonal riemman sums
@_Tomaszeq
@_Tomaszeq Жыл бұрын
I thought it would take over 300 to 500 lines of code, and then suddenly only 125
@code.678
@code.678 Жыл бұрын
My buttons on calculator don't work, do you now how to fix it?
@MiguelArturoAsteteMedran-oi9xw
@MiguelArturoAsteteMedran-oi9xw 7 ай бұрын
Bien
@danielkamau8436
@danielkamau8436 2 жыл бұрын
hi Bro and all here, the equal function is not working, is it mine alone...
@DestinyNiesi
@DestinyNiesi 4 күн бұрын
Hi Bro Code. is there a way for me to create a pytest with this kind of code?
@THEGHOST-gl4ud
@THEGHOST-gl4ud Жыл бұрын
Hi ,bro thank you for this video....I'm using pydroid3. I have followed all the steps but is saying line 40, in ,equation_label = stringVar() NameError : name StringVar is not defined.... Help bro...and everyone
@zekzyarts
@zekzyarts 3 жыл бұрын
Hi Bro Code, what would i do if i wanted to created an extra button called 'pi' and make it when i press it, it solve pi so show me in the box 3.14... ??? how would i do that
@davidcalebpaterson7101
@davidcalebpaterson7101 2 жыл бұрын
Either you can import math and check the available syntax in internet documentation or you create a function containing the operation which will result in the value of pi. for example check some circle that has been measured an take those numbers length of circle devided by it's diameter, and you probably want to make it a float number as well to show all decimals using float() or float.
@guljain1684
@guljain1684 Жыл бұрын
@@davidcalebpaterson7101 hey i wanted to use the log operator but i am not able to do so? can you tell me the code or guide me through it? thanks
@fwblitzz
@fwblitzz 9 ай бұрын
what compiler is this?
@ba.youtube1007
@ba.youtube1007 Жыл бұрын
anyone knows how to add additional feature where you can use your keyboard to use this calculator?
@kubaw3861
@kubaw3861 Жыл бұрын
So I just got here on my journey with Bro and python and maybe its not the most optimal solution but it works, I also added backspace for the keyboard, hope it helps :D from tkinter import * keylist = ["1","2","3","4","5","6","7","8","9","0","-","+","*","/","."] def button_press(num): global equation_text equation_text = equation_text + str(num) equation_label.set(equation_text) def backspace(): global equation_text equation_text = equation_text[:-1] equation_label.set(equation_text) def button_press_keyboard(event): # print(event.char) # print(event.keysym) global equation_text if event.char in keylist: equation_text = equation_text + event.char equation_label.set(equation_text) elif event.keysym == "Return": equals() elif event.keysym == "BackSpace": backspace() elif event.keysym == "c": clear() else: pass def equals(): global equation_text try: total = str(eval(equation_text)) equation_label.set(total) equation_text = total except SyntaxError: equation_label.set("syntax error") equation_text="" except ZeroDivisionError: equation_label.set("arithmetic error") equation_text="" def clear(): global equation_text equation_label.set("") equation_text = "" window = Tk() window.title("Calculator") window.geometry("500x500") window.bind("",button_press_keyboard) equation_text = "" equation_label = StringVar() label = Label(window, textvariable=equation_label, font=('consolas',20), bg="white", width="24", height="2") label.pack() frame = Frame(window) frame.pack() button1 = Button(frame, text=1, height=4, width=9, font=35, command= lambda: button_press(1)) button1.grid(row=0,column=0) button2 = Button(frame, text=2, height=4, width=9, font=35, command= lambda: button_press(2)) button2.grid(row=0,column=1) button3 = Button(frame, text=3, height=4, width=9, font=35, command= lambda: button_press(3)) button3.grid(row=0,column=2) button4 = Button(frame, text=4, height=4, width=9, font=35, command= lambda: button_press(4)) button4.grid(row=1,column=0) button5 = Button(frame, text=5, height=4, width=9, font=35, command= lambda: button_press(5)) button5.grid(row=1,column=1) button6 = Button(frame, text=6, height=4, width=9, font=35, command= lambda: button_press(6)) button6.grid(row=1,column=2) button7 = Button(frame, text=7, height=4, width=9, font=35, command= lambda: button_press(7)) button7.grid(row=2,column=0) button8 = Button(frame, text=8, height=4, width=9, font=35, command= lambda: button_press(8)) button8.grid(row=2,column=1) button9 = Button(frame, text=9, height=4, width=9, font=35, command= lambda: button_press(9)) button9.grid(row=2,column=2) button0 = Button(frame, text=0, height=4, width=9, font=35, command= lambda: button_press(0)) button0.grid(row=3,column=0) plus = Button(frame, text='+', height=4, width=9, font=35, command= lambda: button_press('+')) plus.grid(row=0,column=3) minus = Button(frame, text='-', height=4, width=9, font=35, command= lambda: button_press('-')) minus.grid(row=1,column=3) multiply = Button(frame, text='*', height=4, width=9, font=35, command= lambda: button_press('*')) multiply.grid(row=2,column=3) divide = Button(frame, text='/', height=4, width=9, font=35, command= lambda: button_press('/')) divide.grid(row=3,column=3) equal = Button(frame, text='=', height=4, width=9, font=35, command=equals) equal.grid(row=3,column=2) decimal = Button(frame, text='.', height=4, width=9, font=35, command=lambda: button_press('.')) decimal.grid(row=3,column=1) clearbtn = Button(window, text='Clear', height=4, width=20, font=35, command=clear) clearbtn.pack() window.mainloop()
@Victory-py7lp
@Victory-py7lp 3 ай бұрын
Can someone explain to me what the stringvar and lambda does?
@atoprak00
@atoprak00 Жыл бұрын
Here is the short cut for creating buttons through 9 to 1, order is 9 to 1 not like in Bro's code as 1 to 9, however you can change order if you want; btns = [] btns_nmbr = -1 for x in range(0, 3): for y in range(0, 3): btns_nmbr += 1 btns.append(Button(frame, text=9 - btns_nmbr, height=4, width=9, font=35, command=lambda btns_nmbr=btns_nmbr: button_press(9 - btns_nmbr))) btns[btns_nmbr].grid(row=x, column=y) for other buttons , i think we still need to define it seperately.
@locrilydian
@locrilydian 2 жыл бұрын
i don't understand why we need to put the button commands as lambda functions. aren't they already functions? why can't we just type "command=button_press()". what does lambda change in this case?
@onlyLewds
@onlyLewds 2 жыл бұрын
the lambda function is actually quite important for the making of the whole thing. usually when we make a button its for example: button1 = Button1(window, command = button_press) however, in this case we have to pass in an argument for the button_press() function, with num as its parameter (button_press(num)) by doing button1=Button1(window,command = button_press(1)), we call the function since we added parenthesis at the back of the function, before the button is even pressed. Of course we dont want the command / function bounded to a button to execute before we even press a button, but we cant pass an argument without parathesis (brackets) either, so this is where lambda comes in. The lambda function will prevent the command bounded to the button to activate before we press the button by creating a function on the spot with the expression button_press(1). Hope this helps.
@numerousoriabure459
@numerousoriabure459 Жыл бұрын
@@onlyLewds An anonymous function ୧⁠|⁠ ͡⁠ᵔ⁠ ⁠﹏⁠ ͡⁠ᵔ⁠ ⁠|⁠୨
@abhi-bs6280
@abhi-bs6280 Жыл бұрын
And me as a beginner i can't undastand anything
@ChintaAkhil-hj8up
@ChintaAkhil-hj8up 7 ай бұрын
Here, in def equals the equation text is an empty string then how it can evaluate.. Anyone please explain
@almasshehzadi
@almasshehzadi 4 ай бұрын
During handling of the above exception, another exception occurred: Traceback (most recent call last): File "C:\Users\Shahzad\PycharmProjectsFIRSTFROG\pythonProject3\almas6.py", line 78, in except "Syntax Error": TypeError: catching classes that do not inherit from BaseException is not allowed Process finished with exit code 1 my program have no error...but still output is this.....what can i do
@user-ds9lw9xx5g
@user-ds9lw9xx5g 4 ай бұрын
AttributeError: 'str' object has no attribute 'tk' i am getting this error when i press any buttons and i am not sure why
@Studios9796
@Studios9796 5 ай бұрын
Bro
@nicolatosatti6628
@nicolatosatti6628 Жыл бұрын
Pls help me!!! I don't know how to install tkinter at cmd. I write "pip install tkinter" but the pc gives me this error: ERROR: Could not find a version that satisfies the requirement tkinter (from versions: none) ERROR: No matching distribution found for tkinter How can I solve this problem??
@ranabarham3452
@ranabarham3452 Жыл бұрын
you don`t need cmd, you can install any package from pycharm itself. go to file(In the upper corner of the program), then press at sittings button, after that press (pythonProject), then choose Python Interpreter, you will find a little plus sign, press at it, write tkinter and install it. (you can use this method to install any kind of packages on pycharm).. i hope i could help you.
@amenkalai8442
@amenkalai8442 9 ай бұрын
can someone plz tell me why he used lambda function I still don't get it ?
@clivegreen7139
@clivegreen7139 8 ай бұрын
I get your confusion. It *looks* as if writing "command=somefunction()" will do what you want, but don't be misled; when you run your program, Python will actually call somefunction() immediately AS PART OF SETTING UP YOUR BUTTON. This is not what you want. Instead, using a lambda expression here tells simply Python to run somefunction() ONLY if and when the button is clicked.
@cattooo7273
@cattooo7273 10 ай бұрын
comment dropped
@vtWub
@vtWub Жыл бұрын
I only have 1 problem, whenever I am pressing the buttons the text is not showing. I am currently using pycharm on my mac. Is there a reason for this?
@jaspreetsingh7441
@jaspreetsingh7441 Жыл бұрын
same situation bro... i don't know why
@fwblitzz
@fwblitzz 9 ай бұрын
I figured it out, I compared the code and for me it was on the label = tk.Label(window, textvariable=equation_text line. the text part should be label.
@clashoflegends7035
@clashoflegends7035 12 күн бұрын
Why there is no clear button
@DestinyNiesi
@DestinyNiesi 4 күн бұрын
And how can this code be used on a pytest?I need answers too
@Eagleman9191
@Eagleman9191 6 ай бұрын
Iran left the chat
@arpanshah355
@arpanshah355 10 ай бұрын
comment
@coriesalen6966
@coriesalen6966 7 ай бұрын
THANK YOU @BroCodez 😘
@Xynex11
@Xynex11 5 ай бұрын
@arpanshah355
@arpanshah355 10 ай бұрын
comment
Build this JS calculator in 15 minutes! 🖩
15:20
Bro Code
Рет қаралды 355 М.
3 PYTHON AUTOMATION PROJECTS FOR BEGINNERS
17:00
Internet Made Coder
Рет қаралды 1,5 МЛН
MOM TURNED THE NOODLES PINK😱
00:31
JULI_PROETO
Рет қаралды 21 МЛН
1 класс vs 11 класс (неаккуратность)
01:00
🍟Best French Fries Homemade #cooking #shorts
00:42
BANKII
Рет қаралды 43 МЛН
CS50R - Lecture 2 - Transforming Data
1:38:25
CS50
Рет қаралды 486
The Origins of Hacker Culture
11:16
Internet Underground
Рет қаралды 1,5 М.
Build A Simple Calculator App - Python Tkinter GUI Tutorial #5
18:05
Simple GUI Calculator in Python
22:51
NeuralNine
Рет қаралды 239 М.
Python Object Oriented Programming in 10 minutes 🐍
10:04
Bro Code
Рет қаралды 341 М.
Modern Graphical User Interfaces in Python
11:12
NeuralNine
Рет қаралды 1,4 МЛН
5 Useful F-String Tricks In Python
10:02
Indently
Рет қаралды 250 М.
5 Good Python Habits
17:35
Indently
Рет қаралды 349 М.
Топ-3 суперкрутых ПК из CompShop
1:00
CompShop Shorts
Рет қаралды 470 М.
How charged your battery?
0:14
V.A. show / Магика
Рет қаралды 3,4 МЛН
cool watercooled mobile phone radiator #tech #cooler #ytfeed
0:14
Stark Edition
Рет қаралды 7 МЛН