简体   繁体   中英

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

2) Line 6: The rectangle's arguments must be Point objects, eg 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.

4) Your error seems to suggest the graphics module is not loading tkinter correctly. If you have been messing with the module code, it may be easiest to download the module again rather than try to fix it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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