Когда я пытаюсь получить доступ к атрибутам определенного класса, который я определил, я получаю сообщение об ошибке:
Traceback (most recent call last):
File "H:/PythonCodes/#####/####.py", line 73, in <module>
print(ReadinOut.dataList)
AttributeError: 'logfileOpen' object has no attribute 'dataList'
Я только начинаю пытаться использовать tkinter для создания GUI в Python.Ошибка возникает всякий раз, когда я пытаюсь получить доступ к атрибутам класса, например, если я набираю Object.Attribute
.
from tkinter import filedialog
from tkinter import *
root = Tk()
class logfileOpen(object):
def __init__(self, parent):
self.parent = parent
def fileOpen(self):
filename = filedialog.askopenfilename(initialdir="/", title="Select file", filetypes=(("xvi log files", "*.log"), ("all files", "*.*")))
self.Filename = filename
# print (filename)
def readlogFile(self):
with open(self.Filename, 'r') as a: # Reading in from the file.
for line in a:
typeofevent = line.split(' ')
if len(line) > 2:
if typeofevent[3] == "[Error]":
print(line)
a.close()
def storeEvents(self):
datalist = []
with open(self.Filename, 'r') as b: # Reading in from the file.
for line in b:
typeofevent = line.split(' ')
if len(line) > 2:
datalist.append(typeofevent)
b.close()
self.dataList = datalist
def openfileroutine(self):
self.fileOpen()
self.storeEvents
class GraphicsStuff:
def __init__(self, graphichandle):
self.graphicHandle = graphichandle
def Labels(self, Texttodisplay, WheretoPutLabels):
self.L1 = Label(self.graphicHandle, text=Texttodisplay)
self.L1.pack(side=WheretoPutLabels)
def Inputs(self, WheretoPutInputs):
self.E1 = Entry(self.graphicHandle, bd=5)
self.E1.pack(side=WheretoPutInputs)
def TextBox(self):
self.filedirector = Text(self.graphicHandle)
self.filedirector.pack()
def PushButton(self, Command, WheretoPutPush):
self.openfilebutton = Button(self.graphicHandle, text="Select File", fg="red", command=Command)
self.openfilebutton.pack()
ReadinOut = logfileOpen(root)
Graphics = GraphicsStuff(root)
Graphics.Labels('Open File', 'left')
Graphics.Inputs('right')
Graphics.TextBox()
Graphics.PushButton(ReadinOut.openfileroutine, 'right')
print(ReadinOut.dataList)
# GraphicsStuff.openfilebutton.bind('<Button-1>', print("HELLO"))
# testfileclass.readlogFile()
# testfileclass.storeEvents()
# print (testfileclass.dataList)
root.mainloop()