Last active
July 13, 2021 12:16
-
-
Save rodrigogiraoserrao/3b3d301710da3da80ece693de068e3c9 to your computer and use it in GitHub Desktop.
One-expression calculator.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# A Tkinter calculator in a single Python *expression* | |
# See https://www.reddit.com/r/Python/comments/ojab0n/i_see_your_17_loc_calculator_and_i_raise_you_a/ | |
(tk := __import__("tkinter")) and (bt_draw := lambda k, c, l: (bt := tk.Button(w, text=k, command=lambda: bt_press(k), width=6)) and bt.grid(column=c, row=l)) and (update := lambda t: d.config(text=t)) and (bt_press := lambda k: update("") if k == "C" else update(d["text"][:-1]) if k == "<" else update(str(round(eval(d["text"]), 6))) if k == "=" else update(d["text"] + k)) and (w := tk.Tk()) and w.title("TKalc") or (d := tk.Label(w, text="")) and d.grid(column=0, row=0, columnspan=5) or [bt_draw(k, n%4 + 1, n//4 + 1) for n, k in enumerate("()C<789/456*123-.0=+")] and w.mainloop() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment