Untitled
unknown
plain_text
a year ago
1.2 kB
5
Indexable
from graphics import * # Define colors TURQUOISE = color_rgb(64, 224, 208) # Function to create a button def create_button(win, x, y, width, height, label): button = Rectangle(Point(x, y), Point(x + width, y + height)) button.setFill(TURQUOISE) button.draw(win) text = Text(Point(x + width / 2, y + height / 2), label) text.setSize(14) text.draw(win) return button # Function to handle button clicks def button_click(button, click_point): if click_point is not None: p1 = button.getP1() p2 = button.getP2() if p1.getX() < click_point.getX() < p2.getX() and p1.getY() < click_point.getY() < p2.getY(): return True return False # Main function def main(): win = GraphWin("Turquoise Calculator", 400, 400) # Create button button = create_button(win, 150, 150, 100, 50, "Click Me") while True: click_point = win.checkMouse() if click_point is not None: if button_click(button, click_point): print("Button clicked") if win.checkKey() == "q": break win.close() if __name__ == "__main__": main()
Editor is loading...
Leave a Comment