Advertisement
Guest User

Add up graphic

a guest
Nov 19th, 2019
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.23 KB | None | 0 0
  1. # Imports graphics
  2. from graphics import*
  3.  
  4.  
  5. def main():
  6.  
  7. # Draws window
  8. win = GraphWin("Entry", 300, 300)
  9.  
  10. # Left input box
  11. leftInput = Entry(Point(90, 120), 8)
  12. leftInput.draw(win)
  13.  
  14. # Right input box
  15. rightInput = Entry(Point(200, 120), 8)
  16. rightInput.draw(win)
  17.  
  18. # The addition sign between the input boxes
  19. addLabel = Text(Point (145, 120), "+")
  20. addLabel.draw(win)
  21.  
  22. # The add button rectangle set to white
  23. addButton = Rectangle(Point(115, 140), Point(175, 170))
  24. addButton.setFill("white")
  25. addButton.draw(win)
  26.  
  27. # Text over the add button rectangle to let the user know where to click
  28. addButtonText = Text(Point(145, 155), "Add")
  29. addButtonText.draw(win)
  30.  
  31.  
  32. # Checks if user clicked in the box and if they have to add together the inputed numbers and then print it out next to the boxes
  33. while True:
  34. if win.getMouse().getX() <= 175 and win.getMouse().getX() >= 115 and win.getMouse().getY() <= 170 and win.getMouse().getY() >= 140:
  35. addSum = int(leftInput.getText()) + int(rightInput.getText())
  36. sumLabel = Text(Point(250, 120), str(addSum))
  37. sumLabel.undraw()
  38. sumLabel.draw(win)
  39.  
  40. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement