我用python创建了一个小型windows应用程序。我的代码刚才还在运行。现在它显示出一些错误。我很清楚这是怎么发生的。刚才代码运行得很好。现在出现了错误。我的代码:
import tkinter as tk
from PIL import ImageTk
class MyApp(Frame):
def __init__(self,parent):
Frame.__init__(self,parent)
self.master.title("Music Library")
self.parent=parent
self.images = []
self.createUI()
def createUI(self):
self.grid()
raw_data=Image.open("pic.jpg")
image = ImageTk.PhotoImage(raw_data)
label=tk.Label(image = image)
self.images.append(image)
label.grid(column=0,row=0)
btn = tk.Button(text="Click Me")
btn.grid(column=0,row=0)
root=tk.Tk()
app=MyApp(root)
app.mainloop()
错误是:
Traceback (most recent call last):
File "C:\Python34\Lib\site-packages\pythonwin\pywin\framework\scriptutils.py", line 323, in RunScript
debugger.run(codeObject, __main__.__dict__, start_stepping=0)
File "C:\Python34\Lib\site-packages\pythonwin\pywin\debugger\__init__.py", line 60, in run
_GetCurrentDebugger().run(cmd, globals,locals, start_stepping)
File "C:\Python34\Lib\site-packages\pythonwin\pywin\debugger\debugger.py", line 654, in run
exec(cmd, globals, locals)
File "D:\DeepakK\Python programs\Background Image.py", line 1, in <module>
import tkinter as tk
NameError: name 'Frame' is not defined
您应该在
Frame
前面加上tk
(如上所述)或使用from tkinter import *
,然后像以前那样调用Frame
。你知道吗相关问题 更多 >
编程相关推荐