我在tkinter python中编写了一个hello world应用程序,但我收到了下一条消息:'module'对象没有属性'Frame'
import _tkinter as tk
这是错误
class Application(tk.Frame): def __init__(self, master=None): tk.Frame.__init__(self, master) self.pack() self.createWidgets() def createWidgets(self): self.hi_there = tk.Button(self) self.hi_there["text"] = "Hello World\n(click me)" self.hi_there["command"] = self.say_hi self.hi_there.pack(side="top") self.QUIT = tk.Button(self, text="QUIT", fg="red", command=root.destroy) self.QUIT.pack(side="bottom") def say_hi(self): print("hi there, everyone!") root = tk.Tk() app = Application(master=root) app.mainloop()
为什么会这样?
请勿将文件称为tkinter.py
,如果需要,请重命名。