Facebook
From Diminutive Sloth, 4 Years ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 138
  1. from tkinter import *
  2.  
  3. window = Tk()
  4. window.title("Zdanie 4")
  5. window.geometry('350x200')
  6. number1 = 0
  7. number2 = 0
  8. result = 0
  9. temp = 0
  10. help = 0
  11. label1 = Label(text=result).grid(column=7,row=2)
  12. label2 = Label(text="wartosc1:").grid(column=6,row=0)
  13. label3 = Label(text="wartosc2:").grid(column=6,row=1)
  14. label4 = Label(text=number1).grid(column=7,row=0)
  15. label6 = Label(text="wynik:").grid(column=6,row=2)
  16. label5 = Label(text=number2).grid(column=7,row=1)
  17. def clicknumber(x):
  18.     if temp==0:
  19.         global number1
  20.         number1 *= 10
  21.         number1 += x
  22.         #print(number1)
  23.         label4 = Label(text=number1).grid(column=7, row=0)
  24.     else:
  25.         global number2
  26.         number2 *= 10
  27.         number2 += x
  28.         #print(number1)
  29.         label5 = Label(text=number2).grid(column=7, row=1)
  30.    # return number1
  31. def clickaction(x):
  32.     global temp
  33.     global help
  34.     help = x
  35.     temp = temp+1
  36.     #print(help)
  37. def clickc(x):
  38.     global temp
  39.     global help
  40.     global number1
  41.     global number2
  42.     global result
  43.     number1 = x
  44.     number2 = x
  45.     help = x
  46.     temp = x
  47.     result = x
  48.     label4 = Label(text=number1).grid(column=7, row=0)
  49.     label5 = Label(text=number2).grid(column=7, row=1)
  50.     label1 = Label(text=result).grid(column=7, row=2)
  51. def clickrow():
  52.     global result
  53.     if help == 1:
  54.         result = number1 + number2
  55.     if help == 2:
  56.         result = number1 - number2
  57.     if help == 3:
  58.         result = number1 * number2
  59.     if help == 4:
  60.         result = number1 / number2
  61.     label1 = Label(text=result).grid(column=7, row=2)
  62. btnnumbers = [
  63. Button(window, text="1",command=lambda:clicknumber(1)),Button(window, text="2",command=lambda:clicknumber(2)),
  64. Button(window, text="3",command=lambda:clicknumber(3)),Button(window, text="4",command=lambda:clicknumber(4)),
  65. Button(window, text="5",command=lambda:clicknumber(5)),Button(window, text="6",command=lambda:clicknumber(6)),
  66. Button(window, text="7",command=lambda:clicknumber(7)),Button(window, text="8",command=lambda:clicknumber(8)),
  67. Button(window, text="9",command=lambda:clicknumber(9))
  68. ]
  69. btnrow = Button(window, text="=",command=lambda:clickrow()).grid(column=1,row=4)
  70. btnc = Button(window, text="C",command=lambda:clickc(0)).grid(column=0,row=4)
  71. btnactions = [Button(window, text="+",command=lambda:clickaction(1)),
  72.               Button(window, text="-",command=lambda:clickaction(2)),
  73.               Button(window, text="*",command=lambda:clickaction(3)),
  74.               Button(window, text="/",command=lambda:clickaction(4))]
  75. #btn1 = Button(window, text="1")
  76. for x in range(0,3):
  77.     btnnumbers[x].grid(column=x,row=0)
  78. for x in range(3,6):
  79.     btnnumbers[x].grid(column=x-3,row=1)
  80. for x in range(6,9):
  81.     btnnumbers[x].grid(column=x-6,row=2)
  82. for x in range(0,3):
  83.     btnactions[x].grid(column=4,row=x)
  84. btnactions[3].grid(column=2,row=4)
  85.  
  86.  
  87.  
  88.  
  89.  
  90. window.mainloop()

Replies to Untitled rss

Title Name Language When
Re: Untitled Burly Pheasant text 4 Years ago.