Python Turtle 模块的编写在屏幕上没有显示出来。

huangapple go评论63阅读模式
英文:

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()

Python Turtle 模块的编写在屏幕上没有显示出来。

英文:

You forgot to add parentheses starting_screen = StartingScreen.

it should we like this


starting_screen = StartingScreen()

Python Turtle 模块的编写在屏幕上没有显示出来。

huangapple
  • 本文由 发表于 2023年6月15日 14:50:13
  • 转载请务必保留本文链接:https://go.coder-hub.com/76479829.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定