【问题标题】:Move origin from center to top left corner in Python turtle?在Python乌龟中将原点从中心移动到左上角?
【发布时间】:2017-11-25 09:20:45
【问题描述】:

我希望左上角为参考点 (0,0)
以及其他坐标表示的原点(x>0,y>0)。 感谢您提供的每一个建议。谢谢。

【问题讨论】:

    标签: python graphics turtle-graphics


    【解决方案1】:

    您可以使用turtle.setworldcoordinates(llx, lly, urx, ury)更改坐标

    文档: https://docs.python.org/3.0/library/turtle.html#turtle.setworldcoordinates

    【讨论】:

    • 在这种情况下工作得很好,但并没有解决我真正的问题。我将 RawTurtle 插入到 tkinter 画布中。但我找不到 RawTurtle.setworldcoordinates 方法,因为我在 turtle.setworldcoordinates 中找到它
    【解决方案2】:

    没有解决我真正的问题。我将 RawTurtle 插入 tkinter 帆布。但我找不到 RawTurtle.setworldcoordinates 方法 正如我在 turtle.setworldcoordinates 中找到的那样

    import tkinter as tk
    import turtle
    
    root = tk.Tk()
    
    canvas = turtle.ScrolledCanvas(root)
    canvas.pack(side=tk.LEFT)
    
    screen = turtle.TurtleScreen(canvas)
    screen.setworldcoordinates(-10, 100, 100, -10)
    
    turtle = turtle.RawTurtle(screen)
    turtle.goto(90, 90)
    
    screen.mainloop()
    

    您将 Tk 画布包裹在 TurtleScreen 中,并在该包裹的画布上创建 RawTurtle。然后就可以使用setworldcoordinates()来操作坐标系了。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-10-30
      • 1970-01-01
      • 1970-01-01
      • 2013-07-25
      • 2023-03-28
      • 1970-01-01
      相关资源
      最近更新 更多