Untitled

 avatar
unknown
plain_text
a year ago
1.1 kB
4
Indexable
import turtle

# Function to draw a button
def draw_button(t, color, x, y, width, height, text):
    t.penup()
    t.goto(x, y)
    t.pendown()
    t.fillcolor(color)
    t.begin_fill()
    for _ in range(2):
        t.forward(width)
        t.left(90)
        t.forward(height)
        t.left(90)
    t.end_fill()
    t.penup()
    t.goto(x + width / 2, y + height / 2)
    t.write(text, align="center", font=("Arial", 12, "normal"))

# Function to handle button clicks
def button_click(x, y):
    if button1_x <= x <= button1_x + button_width and button1_y <= y <= button1_y + button_height:
        print("Button 1 clicked")

# Main function
def main():
    turtle.setup(width=400, height=400)
    wn = turtle.Screen()
    wn.title("Turquoise Calculator")

    tracy = turtle.Turtle()
    tracy.speed(0)

    button_width = 100
    button_height = 50
    button1_x = -150
    button1_y = 100

    # Draw buttons
    draw_button(tracy, "turquoise", button1_x, button1_y, button_width, button_height, "Button 1")

    # Listen for clicks
    wn.listen()
    wn.onclick(button_click)

    turtle.done()

if __name__ == "__main__":
    main()
Editor is loading...
Leave a Comment