我正在尝试编写一个 tkinter 版本的 Flappy Bird,但在使用 tkinter 时遇到了一个从未见过的错误。我到处搜索,并尝试了我能想到的一切。到目前为止,这是我的代码:
from tkinter import *
root = Tk()
canvas = Canvas(root, height=400, width=400)
canvas.pack()
bird = PhotoImage(root, file="L:\\Programming\\Python\\flappyBird\\bird.png")
这是错误:
Traceback (most recent call last):
File "L:\Programming\Python\flappyBird\flappyBird.py", line 5, in <module>
bird = PhotoImage(root, file="L:\\Programming\\Python\\flappyBird\\bird.png")
File "C:\Python34\lib\tkinter\__init__.py", line 3384, in __init__
Image.__init__(self, 'photo', name, cnf, master, **kw)
File "C:\Python34\lib\tkinter\__init__.py", line 3340, in __init__
self.tk.call(('image', 'create', imgtype, name,) + options)
_tkinter.TclError: images may not be named the same as the main window
>>>