MCPcopy Index your code
hub / github.com/geekcomputers/Python / create_button

Function create_button

Snake Game Using Turtle/main.py:46–70  ·  view source on GitHub ↗

Creates a turtle-based button with a label.

(name, x, y, width=120, height=40)

Source from the content-addressed store, hash-verified

44buttons = {} # Dictionary to hold button turtles and their properties
45
46def create_button(name, x, y, width=120, height=40):
47 """Creates a turtle-based button with a label."""
48 if name in buttons and buttons[name]['turtle'] is not None:
49 buttons[name]['turtle'].clear()
50
51 button_turtle = Turtle()
52 button_turtle.hideturtle()
53 button_turtle.penup()
54 button_turtle.speed("fastest")
55
56 button_turtle.goto(x - width/2, y - height/2)
57 button_turtle.color(colors.BUTTON_BORDER_COLOR, colors.BUTTON_BG_COLOR)
58 button_turtle.begin_fill()
59 for _ in range(2):
60 button_turtle.forward(width)
61 button_turtle.left(90)
62 button_turtle.forward(height)
63 button_turtle.left(90)
64 button_turtle.end_fill()
65
66 button_turtle.goto(x, y - 12)
67 button_turtle.color(colors.BUTTON_TEXT_COLOR)
68 button_turtle.write(name, align="center", font=("Lucida Sans", 14, "bold"))
69
70 buttons[name] = {'turtle': button_turtle, 'x': x, 'y': y, 'w': width, 'h': height, 'visible': True}
71
72def hide_button(name):
73 """Hides a button by clearing its turtle."""

Callers 1

manage_buttonsFunction · 0.70

Calls 5

clearMethod · 0.80
speedMethod · 0.80
colorMethod · 0.80
leftMethod · 0.80
forwardMethod · 0.45

Tested by

no test coverage detected