Code:
import tkinter as tk
from tkinter import *
from tkinter import messagebox
root = tk.Tk()
root.geometry ( " 700x500 " )
root.configure ( bg = " light blue " )
label1 = tk.Label ( root , text = " Calculator " , font = ( " Times new roman " , 50 ) , bg = " black " , fg = " white " )
label1.pack()
label1 = tk.Label ( root , text = " #There will be no answer for invalid inputs# " , font = ( " Times new roman " , 15 ) , bg = " red " , fg = " black " )
label1.place ( x = 455 , y = 150 )
k = 100
def b1():
global k
entry1.insert ( k , " 1 " )
k = k-1
def b2():
global k
entry1.insert ( k , " 2 " )
k = k-1
def b3():
global k
entry1.insert ( k , " 3 " )
k = k-1
def b4():
global k
entry1.insert ( k , " 4 " )
k = k-1
def b5():
global k
entry1.insert ( k , " 5 " )
k = k-1
def b6():
global k
entry1.insert ( k , " 6 " )
k = k-1
def b7():
global k
entry1.insert ( k , " 7 " )
k = k-1
def b8():
global k
entry1.insert ( k , " 8 " )
k = k-1
def b9():
global k
entry1.insert ( k , " 9 " )
k = k-1
def b0():
global k
entry1.insert ( k , " 0 " )
k = k-1
def plus():
global k
entry1.insert ( k , " + " )
k = k-1
def minus():
global k
entry1.insert ( k , " - " )
k = k-1
def mul():
global k
entry1.insert ( k , " * " )
k = k-1
def div():
global k
entry1.insert ( k , " / " )
k = k-1
def pt():
global k
entry1.insert ( k , " . " )
k = k-1
def equal():
global k
value1 = entry1.get()
val = eval ( value1 )
entry1.insert ( k , " = " )
k = k-1
entry1.insert ( k , val )
k = k-1
entry1 = tk.Entry ( root )
entry1.configure ( font = ( " Times new roman " , 19 ) )
entry1.place ( x = 505 , y = 210 )
button7 = tk.Button ( root , text = " 7 " )
button7.configure ( font = ( " Times new roman" , 25 ) , width = 3 , height = 1 , bg = " black " , fg = " white " , command = b7 )
button7.place ( x = 495 , y = 280 )
button8 = tk.Button ( root , text = " 8 " )
button8.configure ( font = ( " Times new roman " , 25 ) , width = 3 , height = 1 , bg = " black " , fg = " white " , command = b8 )
button8.place ( x = 565 , y = 280 )
button9 = tk.Button ( root , text = " 9 " )
button9.configure ( font = ( " Times new roman " , 25 ) , width = 3 , height = 1 , bg = " black " , fg = " white " , command = b9 )
button9.place ( x = 635 , y = 280 )
button_plus = tk.Button ( root , text = " + " )
button_plus.configure ( font = ( " Times new roman " , 25 ) , width = 3 , height = 1 , bg = " grey " , fg = " white " , command = plus )
button_plus.place ( x = 705 , y = 280 )
button4 = tk.Button ( root , text = " 4 " )
button4.configure ( font = ( " Times new roman " , 25 ) , width = 3 , height = 1 , bg = " black " , fg = " white " , command = b4 )
button4.place ( x = 495 , y = 350 )
button5 = tk.Button ( root , text = " 5 " )
button5.configure ( font = ( " Times new roman " , 25 ) , width = 3 , height = 1 , bg = " black " , fg = " white " , command = b5 )
button5.place ( x = 565 , y = 350 )
button6 = tk.Button ( root , text = " 6 " )
button6.configure ( font = ( " Times new roman " , 25 ) , width = 3 , height = 1 , bg = " black " , fg = " white " , command = b6 )
button6.place ( x = 635 , y = 350 )
button_minus = tk.Button ( root , text = " - " )
button_minus.configure ( font = ( " Times new roman " , 25 ) , width = 3 , height = 1 , bg = " grey " , fg = " white " , command = minus )
button_minus.place ( x = 705 , y = 350 )
button1 = tk.Button ( root , text = " 1 " )
button1.configure ( font = ( " Times new roman " , 25 ) , width = 3 , height = 1 , bg = " black " , fg = " white " , command = b1 )
button1.place ( x = 495 , y = 420 )
button2 = tk.Button ( root , text = " 2 " )
button2.configure ( font = ( " Times new roman " , 25 ) , width = 3 , height = 1 , bg = " black " , fg = " white " , command = b2 )
button2.place ( x = 565 , y = 420 )
button3 = tk.Button ( root , text = " 3 " )
button3.configure ( font = ( " Times new roman " , 25 ) , width = 3 , height = 1 , bg = " black " ,fg = " white " , command = b3 )
button3.place ( x = 635 , y = 420 )
button_mul = tk.Button ( root , text = " * " )
button_mul.configure ( font = ( " Times new roman " , 25 ) , width = 3 , height = 1 , bg = " grey " , fg = " white " , command = mul )
button_mul.place ( x = 705 , y = 420 )
button_point = tk.Button ( root , text = " . " )
button_point.configure ( font = ( " Times new roman " , 25 ) , width = 3 , height = 1 , bg = " black " , fg = " white " , command = pt )
button_point.place ( x = 495 , y = 490 )
button0 = tk.Button ( root , text = " 0 " )
button0.configure ( font = ( " Times new roman " , 25 ) , width = 3 , height = 1 , bg = " black " , fg = " white " , command = b0 )
button0.place ( x = 565 , y = 490 )
button_equal = tk.Button ( root , text = " = " )
button_equal.configure ( font = ( " Times new roman " , 25 ) , width = 3 , height = 1 , bg = " red " , fg = " white " , command = equal )
button_equal.place ( x = 635 , y = 490 )
button_div = tk.Button ( root , text = " / " )
button_div.configure ( font = ( " Times new roman " , 25 ) , width = 3 , height = 1 , bg = " grey " , fg = " white " , command = div)
button_div.place ( x = 705 , y = 490 )
root.mainloop()
Output:
0 Comments