Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2020
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.43 KB | None | 0 0
  1. from tkinter import *
  2.  
  3. root = Tk()
  4. root.title("Calculator")
  5.  
  6. e = Entry(root, width=35, borderwidth=5)
  7. e.grid(row=0, column=0, columnspan=3, padx=10, pady=10)
  8.  
  9.  
  10. # e.insert(0,"Enter your name")
  11. def button_click(number):
  12.     current = e.get()
  13.     e.delete(0, END)
  14.     e.insert(0, str(current) + str(number))
  15.  
  16.  
  17. def button_clear():
  18.     e.delete(0, END)
  19.  
  20.  
  21. def button_add():
  22.     first_number = e.get()
  23.     global f_num
  24.     f_num = int(first_number)
  25.     e.delete(0, END)
  26.  
  27.  
  28. def button_equal():
  29.     second_number = e.get()
  30.     e.delete(0, END)
  31.     e.insert(0, f_num + int(second_number))
  32.  
  33.  
  34. rows = [3, 2, 1]
  35. columns = [0, 1, 2]
  36.  
  37. i = 1
  38. for r in rows:
  39.     for c in columns:
  40.         Button(root, text=str(i), padx=40, pady=20, command=lambda: button_click(i)).grid(row=r, column=c)
  41.         i += 1
  42.  
  43. button_0 = Button(root, text="0", padx=40, pady=20, command=lambda: button_click(0)).grid(row=4, column=0)
  44.  
  45. """
  46. button_1 = Button(root, text="1", padx=40, pady=20, command=lambda: button_click(1))
  47. button_2 = Button(root, text="2", padx=40, pady=20, command=lambda: button_click(2))
  48. button_3 = Button(root, text="3", padx=40, pady=20, command=lambda: button_click(3))
  49. button_4 = Button(root, text="4", padx=40, pady=20, command=lambda: button_click(4))
  50. button_5 = Button(root, text="5", padx=40, pady=20, command=lambda: button_click(5))
  51. button_6 = Button(root, text="6", padx=40, pady=20, command=lambda: button_click(6))
  52. button_7 = Button(root, text="7", padx=40, pady=20, command=lambda: button_click(7))
  53. button_8 = Button(root, text="8", padx=40, pady=20, command=lambda: button_click(8))
  54. button_9 = Button(root, text="9", padx=40, pady=20, command=lambda: button_click(9))
  55. button_0 = Button(root, text="0", padx=40, pady=20, command=lambda: button_click(0))
  56.  
  57. button_1.grid(row=3, column=0)
  58. button_2.grid(row=3, column=1)
  59. button_3.grid(row=3, column=2)
  60.  
  61. button_4.grid(row=2, column=0)
  62. button_5.grid(row=2, column=1)
  63. button_6.grid(row=2, column=2)
  64.  
  65. button_7.grid(row=1, column=0)
  66. button_8.grid(row=1, column=1)
  67. button_9.grid(row=1, column=2)
  68. """
  69.  
  70. button_add = Button(root, text="+", padx=39, pady=20, command=button_add)
  71. button_equal = Button(root, text="=", padx=91, pady=20, command=button_equal)
  72. button_clear = Button(root, text="Clear", padx=79, pady=20, command=button_clear)
  73.  
  74. button_clear.grid(row=4, column=1, columnspan=2)
  75. button_add.grid(row=5, column=0)
  76. button_equal.grid(row=5, column=1, columnspan=2)
  77.  
  78. root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement