简体   繁体   English

Zelle图形错误Python

[英]Zelle Graphics Error Python

I have been trying to import Zelle's graphics library into python for a while but I keep getting this error for a short program I created. 一段时间以来,我一直试图将Zelle的图形库导入python,但是我创建的一个简短程序却不断出现此错误。 Traceback (most recent call last): File "D:\\my_stuff\\Desktop\\ConnectFour.py", line 5, in <module> from graphics import* File "C:\\Python33\\lib\\site-packages\\graphics.py", line 1, in <module> class GraphWin(tk.Canvas): NameError: name 'tk' is not defined 追溯(最近一次通话): File "D:\\my_stuff\\Desktop\\ConnectFour.py", line 5, in <module> from graphics import* File "C:\\Python33\\lib\\site-packages\\graphics.py", line 1, in <module> class GraphWin(tk.Canvas): NameError: name 'tk' is not defined
Here is the program just in case: 这是程序,以防万一:

from graphics import*
def main():
    win = GraphWin("Connect Four", 320, 240)
    win.setBackround("white")
    win.setCoords(0,0,7,6)
    board = Rectangle((0,0),(7,6))
    board.draw(win)
    (Tk.Canvas)
main()

I believe the error relates to the tkinter library (which I do have). 我相信该错误与tkinter库有关(我确实有)。 and to the person who said fix the code indentation: I'm new to this so is that (^) better? 对于说修复代码缩进的人:我是新手,这样(^)更好吗?

Several small problems with your code: 您的代码有几个小问题:

1) Line 4: Should be win.setBackground (probably just a typo) 1)第4行:应该是win.setBackground(可能只是一个错字)

2) Line 6: The rectangle's arguments must be Point objects, eg Rectangle(Point(0,0), Point(7,6)) 2)第6行:矩形的参数必须是Point对象,例如Rectangle(Point(0,0),Point(7,6))

3) Line 8: There is no need for this line, Zelle's graphics module takes care of all the tkinter semantics in the background. 3)第8行:不需要此行,Zelle的图形模块负责后台的所有tkinter语义。

4) Your error seems to suggest the graphics module is not loading tkinter correctly. 4)您的错误似乎表明图形模块未正确加载tkinter。 If you have been messing with the module code, it may be easiest to download the module again rather than try to fix it. 如果您一直在弄乱模块代码,那么重新下载该模块而不是尝试对其进行修复可能是最简单的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM