Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python calculator #2

Open
petermb9 opened this issue Aug 17, 2023 · 0 comments
Open

Python calculator #2

petermb9 opened this issue Aug 17, 2023 · 0 comments

Comments

@petermb9
Copy link
Owner

from tkinter import Tk, Label, Button, Entry

class Root(Tk):
def init(self):
super().init()
self.title_label = Label(self, text="A simple eval-based calculator, \nnot for production usage :)")
self.title_label.pack()
self.entry = Entry(self)
self.entry.pack()
self.entry.insert(0, "1+2")
self.label = Label(self, text="")
self.label.pack()
self.button = Button(self, text="enter", command=self.onclick)
self.button.pack()

def onclick(self):
    self.label.configure(text=str(eval(self.entry.get())))

root = Root()
root.mainloop()

![Image](https://github.com/petermb9/my-turtle-python/assets/69215418/069cb864-6eaf-47cf-b53d-a18c429507d9

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant