Question

python crashes when running code

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()

Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

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.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

Hi @anandu4115,

I’m not sure about the reason behind the crashes you are experiencing but I’ll recommend checking out your error_logs. In that error_logs, 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.