本文介绍了带有滚动条的 Python Turtle 窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 Python 新手,并使用海龟图形在 Python 2.7 中编写了一个简单的程序,该程序绘制了分形.我遇到的问题是海龟窗口没有滚动条,所以如果窗口的形状太大,则不可能看到所有内容.用谷歌搜索但没有找到答案.有人可以帮忙吗?

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 have scrollbars, so if the shape is too large for the window, it is impossible to see all of it. Have googled but found no answer. Can anyone help?

推荐答案

turtle 中不需要直接调用 Tkinter 函数来获取滚动条.您只需要调用 turtle.screensize 并设置一个屏幕尺寸,该尺寸至少在其尺寸之一上大于显示窗口.我发现以默认大小打开显示窗口并让用户根据需要调整其大小最方便.

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.

这是一个简短的演示:

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

这篇关于带有滚动条的 Python Turtle 窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-14 18:25