0
I’m creating a program using Python3 and Tkinter. As I am working with classes and the code is giant I cut out only the part that has been error.
I set a function to be used as a Scale command in Tkinter. and so far ok.
However, I also have a Spinbox with the same variable and also put the same function, but when I do this, the function works for Scale, but presents error in Spinbox
def ImgOriginal(self):
try:
global raioMaior, raioMenor,img_teste, framemask, frameResult
ySize, xSize = img_teste.shape
hafY, hafX = int(ySize/2), int(xSize/2)
#Aplicar a transf fourier
transf1 = np.fft.fft2(img_teste)
#Baixas frequencias para o centro
fshift1 = np.fft.fftshift(transf1)
#Mascara
yy,xx = np.mgrid[-hafY:hafY,-hafX:hafX]
distImg = np.sqrt(xx**2+ yy**2)
maskR1 = (distImg > raioMenor.get())
maskR2 = (distImg < raioMaior.get())
maskRadial = np.logical_and(maskR1, maskR2)
#maskAngle = (np.sin(angleImg*2. + angle) >= angleThresh)
#maskImg = np.logical_and(maskAngle, maskRadial)
maskImg = maskRadial
maskImg[hafY,hafX] = True
xmask = ma.make_mask(maskImg)
masked_img = fshift1 * xmask
filtLog = np.log(np.maximum(np.abs(masked_img),1.))
f_ishift1 = np.fft.ifftshift(masked_img)
img_back_mask = np.fft.ifft2(f_ishift1)
imgtratada = np.uint8(np.abs(img_back_mask))
#Modulo na imagem nova
fourier = cv2.resize(filtLog,(300,300))
imagem = PIL.Image.fromarray(np.double(fourier)*10)
img = ImageTk.PhotoImage(imagem)
img_label = Label(framemask, image = img)
img_label.configure(image = img)
img_label.image = img
img_label.place(x = 0, y =0)
imgtratada = cv2.resize(imgtratada,(400,400))
imagem = PIL.Image.fromarray(np.double(imgtratada)*5)
img = ImageTk.PhotoImage(imagem)
img_label = Label(frameResult, image = img)
img_label.configure(image = img)
img_label.image = img
img_label.place(x = 0, y =0)
except AttributeError: pass
Slider1 = Scale(frameScale, width = 5, from_ =0, to =200,resolution = 0.01,length = 800,
orient = HORIZONTAL, variable = raioMenor, command = ImgOriginal)
Slider1.place(x = 1, y = 1 )
Spinbox1 = Spinbox(frameScale, from_ = 0.00, to = 200, increment = 0.01, width = 6,
textvariable = raioMenor, command = ImgOriginal)
Spinbox1.place(x=820, y=15)
Slider2 = Scale(frameScale, width = 5, from_ =0, to =700,resolution = 0.01,length = 800,
orient = HORIZONTAL, variable = raioMaior, command = ImgOriginal)
Slider2.place(x=1, y=30)
Spinbox2 = Spinbox(frameScale, from_ = 0.00, to = 700, increment = 0.01, width = 6,
textvariable = raioMaior,validatecommand = ImgOriginal)
Spinbox2.place(x=820, y=45)
He says that the self argument is missing. But how is it possible to validate the function for the Scale and not for the Spinbox??
I just took a test and when I remove the self argument from my function, the function becomes valid for Spinbox, but not for Scale
Try to put
def ImgOriginal(self=None)
, makes sure that if he defines the self, that’s fine, but if he doesn’t define, that’s fine, too.– Arthur Bacci