Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # -*- coding: utf-8 -*-
- from tkinter import *
- root = Tk()
- root.geometry("205x340")
- solution = None
- screen = Label(root, text = "0", font = "EngraversMT 12")
- screen.pack()
- def print_zero(event):
- if screen["text"] != "0":
- screen["text"] += "0"
- def print_one(event):
- if screen["text"] == "0":
- screen["text"] = "1"
- else:
- screen["text"] += "1"
- def print_two(event):
- if screen["text"] == "0":
- screen["text"] = "2"
- else:
- screen["text"] += "2"
- def print_three(event):
- if screen["text"] == "0":
- screen["text"] = "3"
- else:
- screen["text"] += "3"
- def print_four(event):
- if screen["text"] == "0":
- screen["text"] = "4"
- else:
- screen["text"] += "4"
- def print_five(event):
- if screen["text"] == "0":
- screen["text"] = "5"
- else:
- screen["text"] += "5"
- def print_six(event):
- if screen["text"] == "0":
- screen["text"] = "6"
- else:
- screen["text"] += "6"
- def print_seven(event):
- if screen["text"] == "0":
- screen["text"] = "7"
- else:
- screen["text"] += "7"
- def print_eight(event):
- if screen["text"] == "0":
- screen["text"] = "8"
- else:
- screen["text"] += "8"
- def print_nine(event):
- if screen["text"] == "0":
- screen["text"] = "9"
- else:
- screen["text"] += "9"
- def _enter(event):
- solve = screen["text"].split( )
- if len(solve) == 1:
- pass
- elif solve[1] == "/":
- screen["text"] = str(int(solve[0]) // int(solve[2]))
- elif solve[1] == "*":
- screen["text"] = str(int(solve[0]) * int(solve[2]))
- elif solve[1] == "-":
- screen["text"] = str(int(solve[0]) - int(solve[2]))
- elif solve[1] == "+":
- screen["text"] = str(int(solve[0]) + int(solve[2]))
- def division(event):
- _enter(event)
- screen["text"] += " / "
- def multiply(event):
- _enter(event)
- screen["text"] += " * "
- def _minus(event):
- _enter(event)
- screen["text"] += " - "
- def _plus(event):
- _enter(event)
- screen["text"] += " + "
- def _backspace(event):
- if len(screen["text"]) > 1:
- screen["text"] = screen["text"][:-1:1]
- else:
- screen["text"] = "0"
- def _sqr(event):
- screen["text"] = str(int(screen["text"]) ** 2)
- def _clear(event):
- screen["text"] = "0"
- div = Button(root, text = "/", width = 5, height = 3)
- mul = Button(root, text = "*", width = 5, height = 3)
- backspace = Button(root, text = "<--", width = 5, height = 3)
- minus = Button(root, text = "-", width = 5, height = 3)
- plus = Button(root, text = "+", width = 5, height = 7)
- enter = Button(root, text = "=", width = 5, height = 3)
- seven = Button(root, text = "7", width = 5, height = 3)
- eight = Button(root, text = "8", width = 5, height = 3)
- nine = Button(root, text = "9", width = 5, height = 3)
- four = Button(root, text = "4", width = 5, height = 3)
- five = Button(root, text = "5", width = 5, height = 3)
- six = Button(root, text = "6", width = 5, height = 3)
- one = Button(root, text = "1", width = 5, height = 3)
- two = Button(root, text = "2", width = 5, height = 3)
- three = Button(root, text = "3", width = 5, height = 3)
- zero = Button(root, text = "0", width = 12, height = 3)
- sqr = Button(root, text = "x^2", width = 5, height = 3)
- clear = Button(root, text = "C", width = 5, height = 3)
- zero.bind("<Button-1>", print_zero)
- zero.place(x = 5, y = 280)
- one.bind("<Button-1>", print_one)
- one.place(x = 5, y = 220)
- two.bind("<Button-1>", print_two)
- two.place(x = 55, y = 220)
- three.bind("<Button-1>", print_three)
- three.place(x = 105, y = 220)
- four.bind("<Button-1>", print_four)
- four.place(x = 5, y = 160)
- five.bind("<Button-1>", print_five)
- five.place(x = 55, y = 160)
- six.bind("<Button-1>", print_six)
- six.place(x = 105, y = 160)
- seven.bind("<Button-1>", print_seven)
- seven.place(x = 5, y = 100)
- eight.bind("<Button-1>", print_eight)
- eight.place(x = 55, y = 100)
- nine.bind("<Button-1>", print_nine)
- nine.place(x = 105, y = 100)
- sqr.bind("<Button-1>", _sqr)
- sqr.place(x = 105, y = 40)
- clear.bind("<Button-1>", _clear)
- clear.place(x = 105, y = 280)
- backspace.bind("<Button-1>", _backspace)
- backspace.place(x = 155, y = 40)
- div.bind("<Button-1>", division)
- div.place(x = 5, y = 40)
- mul.bind("<Button-1>", multiply)
- mul.place(x = 55, y = 40)
- minus.bind("<Button-1>", _minus)
- minus.place(x = 155, y = 100)
- plus.bind("<Button-1>", _plus)
- plus.place(x = 155, y = 160)
- enter.bind("<Button-1>", _enter)
- enter.place(x = 155, y = 280)
- root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement