【发布时间】:2016-04-26 18:00:10
【问题描述】:
所以我是 tKinter 的新手,并且在 python 中使用类到我在这里使用它们的程度。我对这个主题做了很多研究,但我很难把它们放在一起。问题是;我的主类下有 def 函数,第一个是 def class_Window(它创建一个电子表格),另一个是 def 按钮(基本上是保存我创建的所有按钮)。我正在使用 tkintertable.Tables.TableCanvas 保存功能制作一个保存表按钮,并制作一个泡菜文件。对于我的生活,我无法弄清楚如何将按钮链接到定义函数中的表类。
我得到的错误是无效语法或没有属性。
任何关于如何解决这个问题的帮助都会很棒
class AccuracyAssessmentApp:
def __init__(self, parent=Tk()):
self.mainWindow = (parent)
self.mainWindow.title("Accuracy Assessment")
self.mainWindow.geometry("1000x700")
self.make_txt()
self.pos_lbl()
self.buttons()
self.class_Window()
self.title_label()
def make_txt(self):
self.text = Text(self.mainWindow, width = 80, height = 40, background = "#A8A8A8")
self.text.pack(expand = TRUE, fill = BOTH)
def pos_lbl(self):
self.pos = Label(self.mainWindow, text = "0,0")
self.pos.place(x=0, y=0)
self.pos1 = Label(self.mainWindow, text = "0,350")
self.pos1.place(x=0, y=350)
self.pos2 = Label(self.mainWindow, text = "500,0")
self.pos2.place(x=500, y=0)
def class_Window(self):
self.tableFrame = Frame()
self.tableFrame.place(x=680,y=200)
self.table = TableCanvas(self.tableFrame, rows=30,cols=2, width=240)
self.table.createTableFrame()
def title_label(self):
self.titleFrame = Frame(self.mainWindow, bg= '#4A766E', relief="raised", bd=10)
self.titleFrame.place(x=385, y=20)
self.title = Label(self.titleFrame, text=("""Accuracy Assessment"""), font=LARGE_FONT, bg= '#4A766E', fg="white", justify="center")
self.title.pack(pady=10, padx=10)
def buttons(self):
Button(self.mainWindow, text="Quit", command=self.mainWindow.destroy).place(x=10,y=665)
Button(self.mainWindow, text="Save", command=self.table.save("AssessmentTable"))
这是我得到的错误:
runfile('I:/Custom_Scripts/Personal/AccuracyAssessment/AccuracyAssessment_v2.py', wdir='I:/Custom_Scripts/Personal/AccuracyAssessment')
Traceback (most recent call last):
File "<ipython-input-1-d9c198c0cd24>", line 1, in <module>
runfile('I:/Custom_Scripts/Personal/AccuracyAssessment/AccuracyAssessment_v2.py', wdir='I:/Custom_Scripts/Personal/AccuracyAssessment')
File "C:\Users\jpc08005\AppData\Local\Continuum\Anaconda2\lib\site-packages\spyderlib\widgets\externalshell\sitecustomize.py", line 699, in runfile
execfile(filename, namespace)
File "C:\Users\jpc08005\AppData\Local\Continuum\Anaconda2\lib\site-packages\spyderlib\widgets\externalshell\sitecustomize.py", line 74, in execfile
exec(compile(scripttext, filename, 'exec'), glob, loc)
File "I:/Custom_Scripts/Personal/AccuracyAssessment/AccuracyAssessment_v2.py", line 79, in <module>
app = AccuracyAssessmentApp()
File "I:/Custom_Scripts/Personal/AccuracyAssessment/AccuracyAssessment_v2.py", line 41, in __init__
self.buttons()
File "I:/Custom_Scripts/Personal/AccuracyAssessment/AccuracyAssessment_v2.py", line 75, in buttons
Button(self.mainWindow, text="Save", command=self.table.save("AssessmentTable"))
AttributeError: AccuracyAssessmentApp instance has no attribute 'table'
【问题讨论】:
-
请显示实际错误。错误和回溯具有描述问题所在以及问题所在的特定信息。
-
请不要把它放在 cmets 中。您可以编辑您的问题。
标签: tkinter tk tkinter-canvas