level 1
聪明大傻瓜
楼主
from tkinter import *
from random import random as rand
from time import sleep
class Game(object):
def __init__(self):
# 名字
self.name = "Block game"
# window
self.window = Tk()
# 背景
bg = Canvas(self.window)
bg.create_image(image = PhotoImage(file = "bg.png"))
bg.pack()
self.window.mainloop()
Game()
报错:
Traceback (most recent call last):
File "c:\Users\guochenming\Desktop\python\index.py", line 17, in <module>
Game()
File "c:\Users\guochenming\Desktop\python\index.py", line 13, in __init__
bg.create_image(PhotoImage("bg.png"))
File "C:\Users\guochenming\AppData\Local\Programs\Python\Python39\lib\tkinter\__init__ return self._create('image', args, kw)
File "C:\Users\guochenming\AppData\Local\Programs\Python\Python39\lib\tkinter\__init__.py", line 2773, in _create
return self.tk.getint(self.tk.call(
_tkinter.TclError: wrong # coordinates: expected 2, got 1
PS C:\Users\guochenming\Desktop\python> & C:/Users/guochenming/AppData/Local/Programs/Python/Python39/python.exe c:/Users/guochenming/Desktop/python/index.py
Traceback (most recent call last):
File "c:\Users\guochenming\Desktop\python\index.py", line 17, in <module>
Game()
File "c:\Users\guochenming\Desktop\python\index.py", line 13, in __init__
bg.create_image(image = PhotoImage(file = "bg.png"))
File "C:\Users\guochenming\AppData\Local\Programs\Python\Python39\lib\tkinter\__init__.py", line 2787, in create_image
return self._create('image', args, kw)
File "C:\Users\guochenming\AppData\Local\Programs\Python\Python39\lib\tkinter\__init__.py", line 2768, in _create
cnf = args[-1]
IndexError: tuple index out of range
2020年11月22日 10点11分
1
from random import random as rand
from time import sleep
class Game(object):
def __init__(self):
# 名字
self.name = "Block game"
# window
self.window = Tk()
# 背景
bg = Canvas(self.window)
bg.create_image(image = PhotoImage(file = "bg.png"))
bg.pack()
self.window.mainloop()
Game()
报错:
Traceback (most recent call last):
File "c:\Users\guochenming\Desktop\python\index.py", line 17, in <module>
Game()
File "c:\Users\guochenming\Desktop\python\index.py", line 13, in __init__
bg.create_image(PhotoImage("bg.png"))
File "C:\Users\guochenming\AppData\Local\Programs\Python\Python39\lib\tkinter\__init__ return self._create('image', args, kw)
File "C:\Users\guochenming\AppData\Local\Programs\Python\Python39\lib\tkinter\__init__.py", line 2773, in _create
return self.tk.getint(self.tk.call(
_tkinter.TclError: wrong # coordinates: expected 2, got 1
PS C:\Users\guochenming\Desktop\python> & C:/Users/guochenming/AppData/Local/Programs/Python/Python39/python.exe c:/Users/guochenming/Desktop/python/index.py
Traceback (most recent call last):
File "c:\Users\guochenming\Desktop\python\index.py", line 17, in <module>
Game()
File "c:\Users\guochenming\Desktop\python\index.py", line 13, in __init__
bg.create_image(image = PhotoImage(file = "bg.png"))
File "C:\Users\guochenming\AppData\Local\Programs\Python\Python39\lib\tkinter\__init__.py", line 2787, in create_image
return self._create('image', args, kw)
File "C:\Users\guochenming\AppData\Local\Programs\Python\Python39\lib\tkinter\__init__.py", line 2768, in _create
cnf = args[-1]
IndexError: tuple index out of range