from tkinter import *
#funktiot
def napsautus(number):
nimi1 = nimi_varasto.get()
nykyne = nimi.get()
nimi.delete (0, END)
nimi.insert(0, str(nykyne)+ str(number))
def tyhjennys():
nimi.delete (0, END)
def plus():
eka_numero = nimi.get()
global e_numero
global math
math = ”plussaaminen”
e_numero = int(eka_numero)
nimi.delete (0, END)
def yhteen():
toka_numero = nimi.get()
nimi.delete (0, END)
#if lauseet
if math == ”miinustaminen”:
nimi.insert (0, e_numero – int(toka_numero))
if math == ”kertominen”:
nimi.insert (0, e_numero * int(toka_numero))
if math == ”jakaminen”:
nimi.insert (0, e_numero / int(toka_numero))
if math == ”plussaaminen”:
nimi.insert (0, e_numero + int(toka_numero))
def kertominen():
eka_numero = nimi.get()
global e_numero
global math
math = ”kertominen”
e_numero = int(eka_numero)
nimi.delete (0, END)
def miinus():
eka_numero = nimi.get()
global e_numero
global math
math = ”miinustaminen”
e_numero = int(eka_numero)
nimi.delete (0, END)
def jako():
eka_numero = nimi.get()
global e_numero
global math
math = ”jakaminen”
e_numero = int(eka_numero)
nimi.delete (0, END)
if math == ”miinustaminen”:
nimi.insert (0, e_numero – int(toka_numero))
if math == ”kertominen”:
nimi.insert (0, e_numero * int(toka_numero))
if math == ”jakaminen”:
nimi.insert (0, e_numero / int(toka_numero))
if math == ”plussaaminen”:
nimi.insert (0, e_numero + int(toka_numero))
#Ikkuna
ikkuna = Tk()
ikkuna.title (”laskin”)
ikkuna.geometry(”325×500”)
ikkuna.configure(background=”black”)
ikkuna.resizable(0,0)
#nappulat
#Lambda on käytännössä pieni funktio joka voi ottaa numeroita.
nappula9 = Button (text = ”9”, width = 15, height = 5, fg=”white”, bg = ”black”, command = lambda:napsautus(9))
nappula9.place (x=0, y=420)
nappula0 = Button (text = ”0”, width = 15, height = 5, fg=”white”, bg = ”black”, command = lambda:napsautus(0))
nappula0.place(x=100, y=420)
nappula = Button(text = ”=”, fg=”white”,bg = ”black”, width = 15, height = 5, command = yhteen)
nappula.place(x=210, y=420)
nappula6 = Button (text = ”6”, width = 15, height = 5, fg=”white”, bg = ”black”, command = lambda: napsautus(6))
nappula6.place (x=0, y=335)
nappula7 = Button(text = ”7”, width = 15, height = 5, fg=”white”, bg = ”black”, command = lambda: napsautus(7))
nappula7.place (x=100, y=335)
nappula8 = Button(text = ”8”, width = 15, height = 5, fg=”white”, bg = ”black”, command = lambda: napsautus(8))
nappula8.place (x=210, y=335)
nappula3 = Button (text = ”3”, width = 15, height = 5, fg=”white”, bg = ”black”, command = lambda: napsautus(3))
nappula3.place (x=0, y= 250)
nappula4 = Button (text = ”4”, width = 15, height = 5, fg=”white”, bg = ”black”, command = lambda: napsautus(4))
nappula4.place (x=100, y=250)
nappula5 = Button (text = ”5”, width = 15, height = 5, fg=”white”, bg = ”black”, command = lambda: napsautus(5))
nappula5.place (x=210, y=250)
nappulaplus = Button (text = ”+”, width = 7, height = 3, fg=”white”, bg = ”black”,command = plus)
nappulaplus.place (x=0, y=165)
nappulaminus = Button (text = ”-”, width = 7, height = 2, fg=”white”, bg = ”black”,command = miinus)
nappulaminus.place (x=0, y=210)
nappulajako = Button (text = ”/”, width = 7, height = 3, fg=”white”, bg = ”black”, command = jako)
nappulajako.place (x=45, y=165)
nappulakerto = Button (text = ”x”, width = 7, height = 2, fg=”white”, bg = ”black”, command = kertominen)
nappulakerto.place (x= 45, y=210)
nappula1 = Button (text = ”1”, width = 15, height = 5, fg=”white”, bg = ”black”, command = lambda: napsautus(1))
nappula1.place (x=100, y=165)
nappula2 = Button (text = ”2”, width = 15, height = 5, fg=”white”, bg = ”black”, command = lambda: napsautus(2))
nappula2.place (x=210, y=165)
nappula_clear = Button (text = ”C”, width = 35, height = 2, fg=”black”, bg = ”red”, font = ”helvetica 11 bold”, command = tyhjennys)
nappula_clear.place (x=0, y=82/1)
#komennot
nimi_varasto = StringVar()
nimi = Entry(textvariable = nimi_varasto, width=10, font = ”none 42”, cursor = ”dot”)
nimi.place(x=5,y=5)
testi = Label(text =”©Luukas Vuonokari”, font=”helvetica 15″, fg=”white”, bg=”black”)
testi.place(x=0, y=136)
ikkuna.mainloop()