我正在使用python圖形模塊(John Zelle)。我以前從來沒有遇到過任何問題,我可能只是忽略了一些東西,但我找不到它。我試圖畫一個tic tac腳趾板。這些行沒有繪製。殼牌說這個錯誤是在graphics.py中,但我從不同的來源redownloaded它,甚至掠過它,並不能找出我做錯了什麼。請幫忙。來自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'並且通過您正在獲取的錯誤。 –
謝謝。是的,這是我得到的同樣的錯誤。這與我的座標有關,因爲當我移除它時,它工作正常。猜猜我需要多練習一下... – Seth
我不認爲這是對你的,你用相同的y座標給它兩個點,所以Y中的差值爲0,它會嘗試用一些除法來縮放(注意最後一行是'/ self.yscale'),所以我只是詛咒庫並使用稍微偏斜的行。 –