[英]line object from graphics.py not drawing
我正在使用python圖形模塊(John Zelle)。 我之前從未遇到過任何問題,我可能只是忽略了一些東西,但我找不到它。 我正在嘗試繪制一個tic tac toe board。 線條沒有插入.Shell說錯誤是在graphics.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
的內部機制進行了一些挖掘之后,我注意到你有一些奇怪的東西:
win.setCoords(8,1,6,1)
這看起來像文檔字符串似乎有點奇怪:
將窗口的坐標設置為從左下角的(x1,y1)到右上角的(x2,y2)。
請注意,如果您使用IDLE,則可以通過使win
global或執行GraphWin.setCoords(
來查看此doc字符串GraphWin.setCoords(
並且docstring應出現在(
因此,您將屏幕定義為從左下角的(8,1)到右上角的(6,1)......等等,什么?
這意味着不僅你的x坐標非常向后,而且線條Line(Point(2,1),Point(2,5))
在8-6
的x范圍內8-6
。
並且畫布的高度從1到1,因為它的高度為0,導致未定義的行為。 (因此ZeroDivisionError
)
我想你想要一個跨度更像:
win.setCoords(0,0,6,7)
這將使您的屏幕上顯示正確的內容,但我希望您能夠適當地調整確切的數字:)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.