I'm trying to create a rectangle with text on top, but the text shows below the rectangle.
How can I make the text go to the front layer?
My code so far:
from turtle import Turtle class Rectangle(Turtle): def __init__(self, x, y, width, height, color='white'): super().__init__() self.penup() self.goto(x, y) self.color(color) self.shape('square') self.shapesize(stretch_wid=(height / 20), stretch_len=(width / 20)) class Writer(Turtle): def __init__(self, x, y): super().__init__() self.penup() self.goto(x, y) self.hideturtle() def writetext(self, text, font="Arial", size=8, textType="normal", color="black", x=None, y=None): if x is None: x = self.xcor() if y is None: y = self.ycor() self.goto(x, y) self.color(color) self.write(text, move=False, align="center", font=(font, size, textType)) class Button(Rectangle): def __init__(self, position, width, height, text, onclick, color="gray"): position = list(position) super().__init__(position[0], position[1], width, height, color) writer = Writer(position[0], position[1]) writer.writetext(text, color="white") self.goto(position[0], position[1]) self.color(color) self.onclick(onclick) def start_game(_arg1=None, _arg2=None): # requires arguments since Python turtle module passes two in when calling it using onclick print('game started') Button((0, 0), 50, 20, 'click me to start the game', start_game) I've been searching on google for over half an hour and couldn't find anything
Button((0, 0), 50, 20, 'click me', start_game)and then when the button is clicked it should execute start_game, which it does, but the problem is that the text that I write appears on the back layer and not on the front layer. (start_gameisn't defined, it's just an example)