错误"'function' object has no attribute 'tk'"



我在窗口中创建了一个标签然后我得到了错误

'function'对象没有属性'tk'

我不明白是怎么回事,因为我有选项菜单在这段代码内,它似乎工作得很好没有标签。

函数如下:

def taxesFrame():
global taxesWindow
global lowTaxVar
global middleTaxVar
global highTaxVar
taxesWindow = Tk()
taxesWindow.title('Taxes')
taxesWindow.state('zoomed')
taxesTitle = Label(taxesFrame, text = "Taxes")
taxesTitle.configure(font=(titlefont))
taxesTitle.pack()
taxesDescription = Label(taxesFrame, text = "Set Your Taxes")
taxesDescription.configure(font=(subtitlefont))
taxesDescription.pack()
lowTaxVar = StringVar(taxesWindow)
lowTaxVar.set("Select Taxes for the Lower Class")
lowTaxRate = OptionMenu(taxesWindow, lowTaxVar, *taxesList)
lowTaxRate.pack()
middleTaxVar = StringVar(taxesWindow)
middleTaxVar.set("Select Taxes for the Middle Class")
middleTaxRate = OptionMenu(taxesWindow, middleTaxVar, *taxesList)
middleTaxRate.pack()
highTaxVar = StringVar(taxesWindow)
highTaxVar.set("Select Taxes for the Upper Class")
highTaxRate = OptionMenu(taxesWindow, highTaxVar, *taxesList)
highTaxRate.pack()
return lowTaxVar, middleTaxVar, highTaxVar

每个tkinter小部件内的第一个位置参数预计为master,但这里您传递的是函数名称(taxesFrame),因此出现错误:

taxesTitle = Label(taxesWindow, text = "Taxes") # Change to taxesWindow
taxesDescription = Label(taxesWindow, text = "Set Your Taxes")

假设taxesWindowLabelmaster

相关内容

最新更新