英文:
Python Turtle module writing doesn't show up on screen
问题
I am looking to create a starting screen for a simple game, this is the StartingScreen class (in starting_screen.py):
from turtle import Turtle
class StartingScreen(Turtle):
def __init__(self):
super().__init__()
self.penup()
self.color("white")
self.hideturtle()
self.write(arg="First to 5 wins!", align="center", font=("Courier", 25, "normal"))
And this is where I call it:
from turtle import Screen
from starting_screen import StartingScreen
screen = Screen()
screen.bgcolor("black")
screen.setup(width=800, height=600)
screen.title("Pong Game")
starting_screen = StartingScreen()
screen.exitonclick()
However when I run it all I get is an empty black screen. Any ideas on how to make it show up?
I have tried just creating a simple turtle and writing with that, which works, but I would like to get it working with its own class.
英文:
I am looking to create a starting screen for a simple game, this is the StartingScreen class (in starting_screen.py):
from turtle import Turtle
class StartingScreen(Turtle):
def __init__(self):
super().__init__()
self.penup()
self.color("white")
self.hideturtle()
self.write(arg="First to 5 wins!", align="center", font=("Courier", 25, "normal"))
And this is where I call it:
from turtle import Screen
from starting_screen import StartingScreen
screen = Screen()
screen.bgcolor("black")
screen.setup(width=800, height=600)
screen.title("Pong Game")
starting_screen = StartingScreen
screen.exitonclick()
However when I run it all I get is an empty black screen. Any ideas on how to make it show up?
I have tried just creating a simple turtle and writing with that, which works, but I would like to get it working with it's own class.
答案1
得分: 1
You forgot to add parentheses starting_screen = StartingScreen
.
it should be like this
starting_screen = StartingScreen()
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论