Python Turtle window with scrollbars

前端 未结 2 1407
时光取名叫无心
时光取名叫无心 2021-02-10 06:57

I am new to Python, and have written a simple program in Python 2.7 using turtle graphics, which draws a fractal shape. The problem I have is that the turtle window doesn\'t hav

2条回答
  •  醉酒成梦
    2021-02-10 07:25

    You don't need to call Tkinter functions directly to get scrollbars in turtle. You just need to call turtle.screensize and set a screen size that's larger than the display window in at least one of its dimensions. I find it most convenient to open the display window at its default size and let the user resize it, if desired.

    Here's a short demo:

    import turtle
    
    win_width, win_height, bg_color = 2000, 2000, 'black'
    
    turtle.setup()
    turtle.screensize(win_width, win_height, bg_color)
    
    t = turtle.Turtle()
    #t.hideturtle()
    #t.speed(0)
    t.color('white')
    
    for _ in range(4):
        t.forward(500)
        t.right(90)
    
    turtle.done()
    

提交回复
热议问题