- from tkinter import *
- window = Tk()
- window.title("Zdanie 4")
- window.geometry('350x200')
- number1 = 0
- number2 = 0
- result = 0
- temp = 0
- help = 0
- label1 = Label(text=result).grid(column=7,row=2)
- label2 = Label(text="wartosc1:").grid(column=6,row=0)
- label3 = Label(text="wartosc2:").grid(column=6,row=1)
- label4 = Label(text=number1).grid(column=7,row=0)
- label6 = Label(text="wynik:").grid(column=6,row=2)
- label5 = Label(text=number2).grid(column=7,row=1)
- def clicknumber(x):
- if temp==0:
- global number1
- number1 *= 10
- number1 += x
- #print(number1)
- label4 = Label(text=number1).grid(column=7, row=0)
- else:
- global number2
- number2 *= 10
- number2 += x
- #print(number1)
- label5 = Label(text=number2).grid(column=7, row=1)
- # return number1
- def clickaction(x):
- global temp
- global help
- help = x
- temp = temp+1
- #print(help)
- def clickc(x):
- global temp
- global help
- global number1
- global number2
- global result
- number1 = x
- number2 = x
- help = x
- temp = x
- result = x
- label4 = Label(text=number1).grid(column=7, row=0)
- label5 = Label(text=number2).grid(column=7, row=1)
- label1 = Label(text=result).grid(column=7, row=2)
- def clickrow():
- global result
- if help == 1:
- result = number1 + number2
- if help == 2:
- result = number1 - number2
- if help == 3:
- result = number1 * number2
- if help == 4:
- result = number1 / number2
- label1 = Label(text=result).grid(column=7, row=2)
- btnnumbers = [
- Button(window, text="1",command=lambda:clicknumber(1)),Button(window, text="2",command=lambda:clicknumber(2)),
- Button(window, text="3",command=lambda:clicknumber(3)),Button(window, text="4",command=lambda:clicknumber(4)),
- Button(window, text="5",command=lambda:clicknumber(5)),Button(window, text="6",command=lambda:clicknumber(6)),
- Button(window, text="7",command=lambda:clicknumber(7)),Button(window, text="8",command=lambda:clicknumber(8)),
- Button(window, text="9",command=lambda:clicknumber(9))
- ]
- btnrow = Button(window, text="=",command=lambda:clickrow()).grid(column=1,row=4)
- btnc = Button(window, text="C",command=lambda:clickc(0)).grid(column=0,row=4)
- btnactions = [Button(window, text="+",command=lambda:clickaction(1)),
- Button(window, text="-",command=lambda:clickaction(2)),
- Button(window, text="*",command=lambda:clickaction(3)),
- Button(window, text="/",command=lambda:clickaction(4))]
- #btn1 = Button(window, text="1")
- for x in range(0,3):
- btnnumbers[x].grid(column=x,row=0)
- for x in range(3,6):
- btnnumbers[x].grid(column=x-3,row=1)
- for x in range(6,9):
- btnnumbers[x].grid(column=x-6,row=2)
- for x in range(0,3):
- btnactions[x].grid(column=4,row=x)
- btnactions[3].grid(column=2,row=4)
- window.mainloop()