Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Imports graphics
- from graphics import*
- def main():
- # Draws window
- win = GraphWin("Entry", 300, 300)
- # Left input box
- leftInput = Entry(Point(90, 120), 8)
- leftInput.draw(win)
- # Right input box
- rightInput = Entry(Point(200, 120), 8)
- rightInput.draw(win)
- # The addition sign between the input boxes
- addLabel = Text(Point (145, 120), "+")
- addLabel.draw(win)
- # The add button rectangle set to white
- addButton = Rectangle(Point(115, 140), Point(175, 170))
- addButton.setFill("white")
- addButton.draw(win)
- # Text over the add button rectangle to let the user know where to click
- addButtonText = Text(Point(145, 155), "Add")
- addButtonText.draw(win)
- # 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
- while True:
- if win.getMouse().getX() <= 175 and win.getMouse().getX() >= 115 and win.getMouse().getY() <= 170 and win.getMouse().getY() >= 140:
- addSum = int(leftInput.getText()) + int(rightInput.getText())
- sumLabel = Text(Point(250, 120), str(addSum))
- sumLabel.undraw()
- sumLabel.draw(win)
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement