George_Ivanov05

calculator

Jun 28th, 2022
1,398
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.90 KB | None | 0 0
  1. from tkinter import *
  2.  
  3. root = Tk()
  4. root.geometry("560x600")
  5. root.title("GOSHO Calculator")
  6.  
  7. entry = Entry(root, width=40)
  8. entry.grid(row=0, column=0, padx=10, pady=10, columnspan=3)
  9.  
  10.  
  11. def clear_screen():
  12.     entry.delete(0, END)
  13.  
  14.  
  15. def press_buttons(button_pressed):
  16.     current_digit = entry.get()
  17.     entry.delete(0, END)
  18.     entry.insert(0, str(current_digit) + button_pressed)
  19.  
  20.  
  21. but1 = Button(root, text='1', padx=40, pady=20, command=lambda: press_buttons('1'))
  22. but1.grid(row=3, column=0)
  23.  
  24. but2 = Button(root, text='2', padx=40, pady=20, command=lambda: press_buttons('2'))
  25. but2.grid(row=3, column=1)
  26.  
  27. but3 = Button(root, text='3', padx=40, pady=20, command=lambda: press_buttons('3'))
  28. but3.grid(row=3, column=2)
  29.  
  30. but4 = Button(root, text='4', padx=40, pady=20, command=lambda: press_buttons('4'))
  31. but4.grid(row=2, column=0)
  32.  
  33. but5 = Button(root, text='5', padx=40, pady=20, command=lambda: press_buttons('5'))
  34. but5.grid(row=2, column=1)
  35.  
  36. but6 = Button(root, text='6', padx=40, pady=20, command=lambda: press_buttons('6'))
  37. but6.grid(row=2, column=2)
  38.  
  39. but7 = Button(root, text='7', padx=40, pady=20, command=lambda: press_buttons('7'))
  40. but7.grid(row=1, column=0)
  41.  
  42. but8 = Button(root, text='8', padx=40, pady=20, command=lambda: press_buttons('8'))
  43. but8.grid(row=1, column=1)
  44.  
  45. but9 = Button(root, text='9', padx=40, pady=20, command=lambda: press_buttons('9'))
  46. but9.grid(row=1, column=2)
  47.  
  48. but0 = Button(root, text='0', padx=40, pady=20, command=lambda: press_buttons('0'))
  49. but0.grid(row=4, column=0)
  50.  
  51. but_clear = Button(root, text="clean", padx=75, pady=20, command=clear_screen)
  52. but_clear.grid(row=4, column=1, columnspan=2)
  53.  
  54. but_equal = Button(root, text="=", padx=90, pady=20)  # , command=press_buttons)
  55. but_equal.grid(row=5, column=1, columnspan=2)
  56.  
  57. but_plus = Button(root, text="+", padx=39, pady=20)  # , command=press_buttons())
  58. but_plus.grid(row=5, column=0)
  59.  
  60. root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment