AttributeError でご迷惑をおかけして本当に申し訳ありませんが、AttributeErrors に関する多くの解決済みの質問に取り組みましたが、コードの何が問題なのかわかりません。
これは私のコードです:
class Base:
def __init__(self):
self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
self.window.set_position(gtk.WIN_POS_CENTER)
self.window.set_size_request(500,500*9/16)
self.window.set_title("pattern_executer")
self.button1 = gtk.Button(" E x i t ")
self.button1.connect("clicked",self.close)
self.button2 = gtk.Button("Plot")
self.button2.connect("clicked",self.plot)
self.button3 = gtk.Button("Search")
self.button3.connect("clicked",self.search)
self.entry1 = gtk.Entry()
self.entry1.connect("changed",self.dir_ch)
self.entry1.set_text("dir1")
self.entry2 = gtk.Entry()
self.entry2.connect("changed",self.dir_ch)
self.entry2.set_text("name")
self.entry3 = gtk.Entry()
self.entry3.connect("changed",self.dir_ch)
self.entry3.set_text("dir2")
#self.label1 = gtk.Label("FUNCTIONS")
fixed1 = gtk.Fixed()
fixed1.put(self.button1,10,250)
fixed1.put(self.button2,10,60)
fixed1.put(self.button3,10,30)
fixed1.put(self.entry1,90,30)
fixed1.put(self.entry2,90,60)
fixed1.put(self.entry3,90,90)
self.window.add(fixed1)
self.window.show_all()
self.window.connect("destroy",self.close)
def run(self,widget):
print "Run ... "
def search(self,widget):
box = (settings[1] - settings[3]/2,settings[2] - settings[4]/2,settings[1] + settings[3]/2,settings[2] + settings[4]/2)
cut1 = im.crop(box)
cut1.show()
def cut(self):
box = (settings[1] - settings[3]/2,settings[2] - settings[4]/2,settings[1] + settings[3]/2,settings[2] + settings[4]/2)
cut1 = im.crop(box)
return cut1
def gpv(self): #get pixel value
data = self.cut()
data = list(data.getdata())
data = np.array(data)
data = data.reshape(settings[4],settings[3])
data = np.flipud(data)
return data
def plot(self,widget):
xlist = np.linspace(0,1.0,settings[3])
ylist = np.linspace(0,1.0,settings[4])
X,Y = np.meshgrid(xlist, ylist)
fig = plt.figure()
fig = plt.contour(X, Y, self.gpv(),settings[0],colors = "k")
fig = plt.contourf(X, Y, self.gpv(),settings[0])
plt.show(fig)
def dir_ch(self,widget):
directories[0] = self.entry1.get_text()
directories[1] = self.entry2.get_text()
directories[2] = self.entry3.get_text()
def close(self,widget,data=None):
print "Closed"
gtk.main_quit()
def main(self):
gtk.main()
if __name__ == "__main__":
base = Base()
base.main()
実行すると、次のエラー メッセージが表示されます。
Traceback (most recent call last):
File "E:\cutter\cutter.py", line 113, in dir_ch
directories[1] = self.entry2.get_text()
AttributeError: Base instance has no attribute 'entry2'
Traceback (most recent call last):
File "E:\cutter\cutter.py", line 114, in dir_ch
directories[2] = self.entry3.get_text()
AttributeError: Base instance has no attribute 'entry3'
私の意見では、面白い問題は、"entry1" は "entry2" や "entry3" とまったく同じですが、何の問題もないということです。これらのエラーが発生する理由を知っていますか?
ご助力ありがとうございます!