[英]Tkinter Frame object will not grid
尝试网格化我在基本绘画程序中创建的框架对象时遇到问题。
出现错误的实例化代码在这里:
from tkinter import *
from Menu import Menu
class Application(Frame):
def __init__(self, master=None):
Frame.__init__(self,master)
self.grid()
self.createWidgets()
def createWidgets(self):
#Imports each of the frames from the collection from the various widgets
menu=Menu()
menu.grid(row=0,column=0,columnspan=2)
app=Application()
app.master.title=('Sample Application')
app.mainloop()
我收到的错误与menu=Menu()
操作有关,并且是:
TypeError: Menu() missing 1 required positional argument: 'Frame'
Menu
对象在这里:
from tkinter import *
import CommandStack
def Menu(Frame):
def __init__(self, master=None):
Frame.__init__(self,master)
self.createWidgets()
def createWidgets(self):
self.new=Button(self,command=CommandStack.new())
self.save=Button(self,command=CommandStack.save())
self.save.grid(row=0,column=1)
self.load=Button(self,command=CommandStack.load())
self.load.grid(row=0,column=2)
我的困惑是该位置错误是如何发生的。 当我给菜单加一个框架( self
)时,使用grid方法却出现此错误:
AttributeError: 'NoneType' object has no attribute 'grid'
我很想念我缺少使用框架的关键部分,但是我不确定是什么。 有什么建议吗?
您似乎希望Menu
是一个类,因此使用__init__
方法将其定义为此类。 但是您而是将Menu
定义为一个函数,因此,您存储在其中的所有函数都只是定义为只能在该函数中使用的代码。 将def Menu
更改为def Menu
class Menu
,应该没问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.