Мы делаем программу для вставки одного изображения на другое изображение. Наша проблема заключается в попытке сохранить имя файла. У нас есть функция explorer, которая хранит путь к файлу в переменную wow и подмигивает. Затем мы запустить программу и получаю ошибку:TheGui экземпляр не имеет атрибута 'read'
AttributeError: TheGui instance has no attribute 'read'
Вот наш код:
import Tkinter
from Tkinter import *
import subprocess
import sys
import tkFileDialog
import PIL
import matplotlib.pyplot as plt # single use of plt is commented out
import os.path
import PIL.ImageDraw
import PIL.Image
bg_size = [1080,1920]
logo_size = [200,200]
seal_size = [200,200]
seal = 0
class TheGui:
global wow
global wink
wow = ""
wink = ""
global in_path
global in_path1
def __init__(self, parent):
#------- frmSetup ----------#
self.frmSetup = Frame(parent, bd=5)
self.frmSetup.pack()
self.inChoices = ('Text', 'Midi')
self.varRadio = IntVar()
self.r1 = Radiobutton(self.frmSetup, text="Convert Text INPUT into Midi OUTPUT",
variable=self.varRadio, value=0, command=self.selRadio)
self.r1.pack(anchor=W)
self.r2 = Radiobutton(self.frmSetup, text="Convert Midi INPUT into Text OUTPUT",
variable=self.varRadio, value=1, command=self.selRadio)
self.r2.pack(anchor=W)
#------- frmSetup ----------#
sep = Frame(parent, width=1, bd=5, bg='black')
sep.pack(fill=X, expand=1)
#------- frmIn ----------#
# http://effbot.org/tkinterbook/tkinter-widget-styling.htm
self.frmIn = Frame(parent, bd=5)
self.frmIn.pack()
self.lblIn = Label(self.frmIn, text='Campaign Background', width=20)
self.lblIn.pack(side=LEFT)
self.inFilePath = StringVar() # http://effbot.org/tkinterbook/entry.htm
self.entIn = Entry(self.frmIn, width=20, textvariable=self.inFilePath)
self.entIn.pack(side=LEFT)
self.btnIn = Button(self.frmIn, text='Browse', command=self.OpenExplorer)
self.btnIn.pack(side=LEFT)
#------- frmIn ----------#
#------- frmOut ----------#
self.frmOut = Frame(parent, bd=5)
self.frmOut.pack()
self.lblOut = Label(self.frmOut, text='Logo Path', width=20)
self.lblOut.pack(side=LEFT)
self.outFilePath = StringVar()
self.entOut = Entry(self.frmOut, width=20, textvariable=self.outFilePath)
self.entOut.pack(side=LEFT)
self.btnOut = Button(self.frmOut, text='Browse', command=self.OpenExplorer1)
self.btnOut.pack(side=LEFT)
#------- frmOut ----------#
sep = Frame(parent, width=1, bd=5, bg='black')
sep.pack(fill=X, expand=1)
#------- frmButtons ----------#
self.frmOut = Frame(parent, bd=5)
self.frmOut.pack()
self.btnConvert = Button(self.frmOut,
text='Convert', command=self.test(wow,wink))
self.btnConvert.pack()
#------- handle commands ----------#
def selRadio(self):
self.lblIn.config(text = self.inChoices[self.varRadio.get()]
+ ' Input File Path')
self.lblOut.config(text = self.inChoices[(self.varRadio.get()+1)%2]
+ ' Output File Path')
print str(self.varRadio.get())
def btnInBrowseClick(self):
rFilepath = askopenfilename(defaultextension='*',
initialdir='.', initialfile='', parent=self.frmIn, title='select a file')
self.inFilePath.set(rFilepath)
print self.entIn.get()
def btnOutBrowseClick(self):
rFilepath = asksaveasfilename(defaultextension='*',
initialdir='.', initialfile='', parent=self.frmIn, title='select a file')
self.outFilePath.set(rFilepath)
print self.entOut.get()
def btnConvertClick(self):
if self.varRadio.get() == 0:
inputTextFilePath = str(self.inFilePath.get())
outputMidiFilePath = str(self.outFilePath.get())
print 'midi 4 txt', inputTextFilePath, outputMidiFilePath
midi24txt.mid4txt(inputTextFilePath, outputMidiFilePath)
else:
inputMidiFilePath = str(self.inFilePath.get())
outputTextFilePath = str(self.outFilePath.get())
print 'midi 2 txt', inputMidiFilePath, outputTextFilePath
midi24txt.mid2txt(inputMidiFilePath, outputTextFilePath)
def OpenExplorer(self):
def main():
Tkinter.Tk().withdraw() # Close the root window
in_path = tkFileDialog.askopenfilename()
wow = in_path
print wow , "\n"
outFilePath.insert(wow)
if __name__ == "__main__":
main()
def OpenExplorer1(self):
def main():
Tkinter.Tk().withdraw() # Close the root window
in_path1 = tkFileDialog.askopenfilename()
wink = in_path1
print wink , "\n"
if __name__ == "__main__":
main()
def test(main_image, logo_image, self):
logo = PIL.Image.open(main_image)
main = PIL.Image.open(logo_image)
img_w, img_h = main_image.size
if seal == 0:
print("We converting a banner its lit")
offset = (0,780)
main.paste(logo, offset)
main.save('out.png')
main.show()
else:
logo.resize(seal_size)
offset = (0,600)
print("We are converting a seal over here")
root = Tk()
my_gui = TheGui(root)
root.mainloop()
Рассматривая код, это, по-видимому, является истинным фактом, что 'TheGUI' не имеет атрибута' read'. Как вы думаете, у этого должен быть этот атрибут? –