# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python 3
#     language: python
#     name: python3
# ---

# +
from tkinter import *
from math import *
from tkinter import messagebox

expression = ""
names = {'sqrt': sqrt, 'powTo': pow}
xpad = 5
ypad = 5
sqrtBool = False
powerCount = 0

def sqRoot():
    global sqrtBool
    
    if sqrtBool == False:
        press('sqrt(')
        sqrtBool = True
    else:
        press(')')
        sqrtBool = False
        
def powTo():
    global powerCount
    
    if powerCount == 0:
        press('powTo(')
        powerCount += 1
    elif powerCount == 1:
        press(',')
        powerCount += 1
    else:
        press(')')
        powerCount = 0
 
# Function to update expressiom
# in the text entry box
def press(num):
    global expression
    expression = expression + str(num)
    equation.set(expression)
 
# Function to evaluate (eval()) the final expression
def equalpress():
    try:
        global expression
        print(expression)
        total = str(eval(expression, names))
        equation.set(total)
        expression = ""

    except: 
        equation.set(" error ")
        expression = ""
 
 
# Function to clear the contents
# of text entry box
def clear():
    global expression
    expression = ""
    equation.set("")
    
def Info():
    messagebox.showinfo("Info","Created by the awesome --> Enter Name <--- ! =O")
  
# Driver code
# Is this file directly run by Python or is it imported
if __name__ == "__main__":
    # create a GUI window
    gui = Tk()
 
    # set the background colour of GUI window
    gui.configure(background="white")
    # set the title of GUI window
    gui.title("LABINF Calculator")
    # set the configuration of GUI window
    gui.geometry("350x200")
    # StringVar() is the variable class
    equation = StringVar()
    # create the text entry box for
    expression_field = Entry(gui, textvariable=equation,bg='grey',fg='white', font=("Calibri 15"), justify=CENTER, state=DISABLED)
    # grid method is used for placing
    expression_field.grid(columnspan=5, ipadx=50, ipady=10)
    equation.set('Enter your expression')
 
    # create a Buttons and place at a particular
    button1 = Button(gui, text=' 1 ', fg='black', bg='light grey',command=lambda: press(1), height=1, width=7)
    button1.grid(row=2, column=0, padx=xpad, pady=ypad)
 
    button2 = Button(gui, text=' 2 ', fg='black', bg='light grey',command=lambda: press(2), height=1, width=7)
    button2.grid(row=2, column=1, padx=xpad, pady=ypad)
    
    button3 = Button(gui, text=' 3 ', fg='black', bg='light grey',command=lambda: press(3), height=1, width=7)
    button3.grid(row=2, column=2, padx=xpad, pady=ypad)
    
    button3 = Button(gui, text=' 4 ', fg='black', bg='light grey',command=lambda: press(4), height=1, width=7)
    button3.grid(row=3, column=0, padx=xpad, pady=ypad)
    
    button3 = Button(gui, text=' 5 ', fg='black', bg='light grey',command=lambda: press(5), height=1, width=7)
    button3.grid(row=3, column=1, padx=xpad, pady=ypad)

    button3 = Button(gui, text=' 6 ', fg='black', bg='light grey',command=lambda: press(6), height=1, width=7)
    button3.grid(row=3, column=2, padx=xpad, pady=ypad)
    
    button3 = Button(gui, text=' 7 ', fg='black', bg='light grey',command=lambda: press(7), height=1, width=7)
    button3.grid(row=4, column=0, padx=xpad, pady=ypad)
    
    button3 = Button(gui, text=' 8 ', fg='black', bg='light grey',command=lambda: press(8), height=1, width=7)
    button3.grid(row=4, column=1, padx=xpad, pady=ypad)
    
    button3 = Button(gui, text=' 9 ', fg='black', bg='light grey',command=lambda: press(9), height=1, width=7)
    button3.grid(row=4, column=2, padx=xpad, pady=ypad)
    
    button3 = Button(gui, text=' 0 ', fg='black', bg='light grey',command=lambda: press(0), height=1, width=7)
    button3.grid(row=5, column=1, padx=xpad, pady=ypad)
    
    dec = Button(gui, text=' , ', fg='black', bg='light grey',command=lambda: press('.'), height=1, width=7)
    dec.grid(row=5, column=2, padx=xpad, pady=ypad)
    
    add = Button(gui, text=' + ', fg='black', bg='orange', command=lambda: press("+"), height=1, width=7)
    add.grid(row=2, column=3, padx=xpad, pady=ypad)
    
    sub = Button(gui, text=' - ', fg='black', bg='orange', command=lambda: press("-"), height=1, width=7)
    sub.grid(row=3, column=3, padx=xpad, pady=ypad)
    
    multi = Button(gui, text=' * ', fg='black', bg='orange', command=lambda: press("*"), height=1, width=7)
    multi.grid(row=4, column=3, padx=xpad, pady=ypad)
    
    div = Button(gui, text=' / ', fg='black', bg='orange', command=lambda: press("/"), height=1, width=7)
    div.grid(row=5, column=3, padx=xpad, pady=ypad)
    
    sqr = Button(gui, text=' ^ ', fg='black', bg='orange', command=lambda: powTo(), height=1, width=7)
    sqr.grid(row=3, column=4, padx=xpad, pady=ypad)
    
    power = Button(gui, text=' √ ', fg='black', bg='orange', command=lambda: sqRoot(), height=1, width=7)
    power.grid(row=4, column=4, padx=xpad, pady=ypad)
 
    equal = Button(gui, text=' = ', fg='black', bg='orange', command=equalpress, height=1, width=7)
    equal.grid(row=5, column=4, padx=xpad, pady=ypad)
 
    clear = Button(gui, text='Clear', fg='white', bg='lightcoral', command=clear, height=1, width=7)
    clear.grid(row=2, column=4, padx=xpad, pady=ypad)
    
    info = Button(gui, text=' Info ', fg='black', bg='light blue',command=lambda: Info(), height=1, width=7)
    info.grid(row=5, column=0, padx=xpad, pady=ypad)
    
    # start the GUI
    gui.mainloop()
# -



StarcoderdataJupyterScriptsDedupFiltered