Question

python crashes when running code

Posted January 2, 2021 424 views
Python

so i was making a gui for a calculator app. ok so when i run the code it opens up python and in my code i added buttons to click on. but when i click on the button in the gui , python crashes for some reason can someone help me?. im writing code in pycharm. pls help me. this is my code:

from tkinter import *
from tkinter import Button
root = Tk()

def num1():
    input("")


root.title("Basic Calculator")
entry = Entry(root, width=50,bg="green", fg="black")
entry.grid()

b1 = Button(root,  text="1", padx=40, pady=20, command=num1)
b2 = Button(root,  text="2", padx=40, pady=20, command=num1)
b3 = Button(root,  text="3", padx=40, pady=20, command=num1)
b4 = Button(root,  text="4", padx=40, pady=20, command=num1)
b5 = Button(root,  text="5", padx=40, pady=20, command=num1)
b6 = Button(root,  text="6", padx=40, pady=20, command=num1)
b7 = Button(root,  text="7", padx=40, pady=20, command=num1)
b8 = Button(root,  text="8", padx=40, pady=20, command=num1)
b9 = Button(root,  text="9", padx=40, pady=20, command=num1)
b0 = Button(root,  text="0", padx=40, pady=20, command=num1)
b_add = Button(root,  text="+", padx=40, pady=20, command=num1)
b_sub = Button(root,  text="-", padx=40, pady=20, command=num1)
b_div = Button(root,  text="/", padx=40, pady=20, command=num1)
b_mul = Button(root,  text="*", padx=40, pady=20, command=num1)
b_cl = Button(root,  text="Clear", padx=40, pady=20, command=num1)
b_equal = Button(root,  text="=", padx=40, pady=20, command=num1)

b1.grid(row=1, column=0)


root.mainloop()
edited by bobbyiliev

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

×
Submit an Answer
1 answer

Hi @anandu4115,

I’m not sure about the reason behind the crashes you are experiencing but I’ll recommend checking out your errorlogs. In that errorlogs, you should be able to get a better understanding at what the exact python error you are experiencing and see if you can fix it.

It might give you a good point to continue your Google search as well.