gui.py
Код: Выделить всё
root = tk.Tk()
canvas = tk.Canvas(root, bg="green")
canvas.pack(fill=tk.BOTH, expand=True)
root.mainloop()
def drawentity(entity):
imgPath = data.getimagepath(entity.img, entity.imgType)
img = None
try:
img = tk.PhotoImage(imgPath)
canvas.create_image(entity.x, entity.y, img)
except IOError as e: print(e)
finally:
if not isinstance(img, type(None)): img.close()
Код: Выделить всё
e = player.Player(100, 200, "Ball_Grayed.png", 3)
gui.drawentity(e)
Код: Выделить всё
cd = os.path.join(os.getcwd(), "resources")
def getimagepath(imgName, imgType):
return os.path.join(cd, imgType, imgName)
Код: Выделить всё
File "S:\Users\Sean\Google Drive\cs\personal\BallAdventure\main.py", line 12, in
gui.drawentity(e)
File "S:\Users\Sean\Google Drive\cs\personal\BallAdventure\gui.py", line 22, in drawentity
img = tk.PhotoImage(imgPath)
File "C:\Users\Sean\AppData\Local\Programs\Python\Python310\lib\tkinter\__init__.py", line 4093, in __init__
Image.__init__(self, 'photo', name, cnf, master, **kw)
File "C:\Users\Sean\AppData\Local\Programs\Python\Python310\lib\tkinter\__init__.py", line 4026, in __init__
master = _get_default_root('create image')
File "C:\Users\Sean\AppData\Local\Programs\Python\Python310\lib\tkinter\__init__.py", line 297, in _get_default_root
raise RuntimeError(f"Too early to {what}: no default root window")
RuntimeError: Too early to create image: no default root window
Подробнее здесь: https://stackoverflow.com/questions/728 ... oot-window