Python 2.7 类Tk没有属性';框架';
运行简单的Tkinter程序时会发生属性错误。我已经检查了教程和相关问题,但我仍然不知道如何修复它Python 2.7 类Tk没有属性';框架';,python-2.7,tkinter,Python 2.7,Tkinter,运行简单的Tkinter程序时会发生属性错误。我已经检查了教程和相关问题,但我仍然不知道如何修复它 import Tkinter as Tk class Application(Tk.Frame): def __init__(self, master=None): Tk.Frame.__init__(self, master) self.grid() self.createWidgets() def createWidgets(self): self.quitB
import Tkinter as Tk
class Application(Tk.Frame):
def __init__(self, master=None):
Tk.Frame.__init__(self, master)
self.grid()
self.createWidgets()
def createWidgets(self):
self.quitButton = Tk.Button(self, text='Quit',
command=self.quit)
self.quitButton.grid()
app = Application()
app.master.title('Sample application')
app.mainloop()
错误消息显示:
class Application(Tk.Frame):
AttributeError: class Tk has no attribute 'Frame'
有人能帮我吗 您永远不会将tk窗口传递给应用程序
import Tkinter # careful with importing it as Tk because Tk is already a sub module of Tkinter
class Application(Tkinter.Frame):
def __init__(self, master=None):
Tkinter.Frame.__init__(self, master)
self.grid()
self.createWidgets()
def createWidgets(self):
self.quitButton = Tkinter.Button(self, text='Quit',
command=self.quit)
self.quitButton.grid()
window = Tkinter.Tk()
app = Application(master=window)
app.master.title('Sample application')
app.mainloop()
改进您的缩进是否有名为Tkinter.py或类似文件?