我使用的是python图形模块(johnzelle)。我以前从来没有遇到过问题,我可能只是忽略了一些东西,但我找不到它。我试着画一个图板。线没有画进去。外壳说错误在图形.py但我已经从不同的来源重新下载了它,甚至浏览了一遍,却不知道我做错了什么。请帮忙。在
#here is my code sample
#import graphics library
from graphics import *
#build interface
def interface():
win = GraphWin("Tic Tac Toe", 600,700)
win.setCoords(8,1,6,1)
#horizontal line #1
h1 = Line(Point(2,1),Point(2,5))
h1.draw(win)
#...there is more but it's repetitive so I won't waste time.
>>> interface()
Traceback (most recent call last):
File ".../test.py", line 12, in <module>
interface()
File ".../test.py", line 10, in interface
h1.draw(win)
File "/LIB/graphics.py", line 450, in draw
self.id = self._draw(graphwin, self.config)
File "/LIB/graphics.py", line 627, in _draw
x1,y1 = canvas.toScreen(p1.x,p1.y)
File "/LIB/graphics.py", line 335, in toScreen
return self.trans.screen(x,y)
File "/LIB/graphics.py", line 386, in screen
ys = (self.ybase-y) / self.yscale
ZeroDivisionError: float division by zero
在深入研究了
graphics.py
的内在机制之后,我注意到你有一点感性:这在我看来有点奇怪,看看docstring:
注意,如果您使用的是IDLE,则可以通过使
win
全局或执行GraphWin.setCoords(
来查看此doc字符串,并且docstring应该出现在(
上所以你要定义你的屏幕从左下角的(8,1)到右上角的(6,1)。。。等等,什么?在
这意味着不仅你的x坐标非常向后,而且}的x跨度内。在
Line(Point(2,1),Point(2,5))
线甚至不在{画布的高度从1到1,因为它的高度0会导致未定义的行为。(因此
ZeroDivisionError
)我想你想要的跨度更像:
^{pr2}$这将使内容正确显示在您的屏幕上,尽管我希望您适当地调整确切的数字:)
相关问题 更多 >
编程相关推荐