How to fix TypeError: penup() missing 1 required positional argument: 'self' when trying to make a border on Tkinter

How to fix TypeError: penup() missing 1 required positional argument: 'self' when trying to make a border on Tkinter

我收到此错误: 类型错误:penup() 缺少 1 个必需的位置参数:'self'

从这段代码:(我希望在我的 window 上有一个边框,但我得到了一个错误。)

    #Draw border
    mypen = turtle.Turtle
    mypen.penup()
    mypen.setposition(-300,-300)
    mypen.pendown()
    mypen.pensize(3)

I'm expecting to get a border on my window but I get an error.

您的问题是 mypen = turtle.Turtle 正在获取对 class 本身的引用,而不是 class 的对象。方法 penup() 要求您有一个 class 的对象来调用它,因为它不是静态的。您可以通过将第一行更改为:

来解决此问题
mypen = turtle.Turtle()