Advertisement
dimkiriakos

calculator

Mar 20th, 2022
1,042
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.59 KB | None | 0 0
  1. from tkinter import Tk, Label, Button, Entry
  2. class Root(Tk):
  3.     def __init__(self):
  4.         super().__init__()
  5.         self.title_label = Label(self, text="Python Calculator")
  6.         self.title_label.pack()
  7.         self.entry = Entry(self)
  8.         self.entry.pack()
  9.         self.entry.insert(0, "1+2")
  10.         self.label = Label(self, text="")
  11.         self.label.pack()
  12.         self.button = Button(self, text="Compute", command=self.onclick)
  13.         self.button.pack()
  14.     def onclick(self):
  15.         self.label.configure(text=str(eval(self.entry.get())))
  16. root = Root()
  17. root.mainloop()
  18.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement