0

I'm tryting too put two windows as panel A and panelB but i'm getting following error

if PanelA is None or PanelB if None: NameError: name 'panelA' is not defined

from tkinter import *
from PIL import Image, ImageTk
from tkinter import filedialog
import cv2

def select_image():
        global panelA, panelB
        path = filedialog.askopenfilename()
        if len(path) > 0:
                image = cv2.imread(path)
                gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
                edged = cv2.Canny(gray, 50, 100)
                image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
                image = Image.fromarray(image)
                edged = Image.fromarray(edged)
                image = ImageTk.PhotoImage(image)
                edged = ImageTk.PhotoImage(edged)    
        if panelA is None or panelB is None:
                panelA = Label(image=image)
                panelA.image = image
                panelA.pack(side="left", padx=10, pady=10)
                panelB = Label(image=edged)
                panelB.image = edged
                panelB.pack(side="right", padx=10, pady=10)
        else:
                panelA.configure(image=image)
                panelB.configure(image=edged)
                panelA.image = image
                panelB.image = edged
root = Tk()
panelA = None
panelB = None

btn = Button(root, text="Select an image", command=select_image)
btn.pack(side="bottom", fill="both", expand="yes", padx="10", pady="10")

root.mainloop()
1
  • 1
    Please fix your indentation. This question is not answerable as it is. Commented Apr 16, 2019 at 9:58

2 Answers 2

1

You define global variable but you also need to initialize them if you want to compare them in an if statement :

global panelA, panelB
panelA, panelB = None, None
Sign up to request clarification or add additional context in comments.

Comments

0

Please fix your indentation.and panelA, panelB =''

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.