I have the following simplified code from my project. My error lies in the line
self.displayimg = tk.Button(self.frame, text = 'Display', width = 25, command = lambda: show)
The error message spyder gives me is that the name 'show' is not defined, even though it is a function I clearly define in the class.
from PIL import Image, ImageTk
import matplotlib.pyplot as plt
x = 100
y = 100
xtmi = 200
xtma = 205
xs = 1024
ytmi = 500
ytma = 505
ys = 768
xarr = np.zeros(x)
yarr = np.zeros(y)
output = np.meshgrid(xarr,yarr)
output=output[0]
def mkPIL(array):
im = Image.fromarray(np.uint8(array))
return im
im = mkPIL(output)
plt.imshow(im, cmap='gray')
import tkinter as tk
from tkinter import Canvas, Label
root = tk.Tk()
root.mainloop()
class Manipulation:
def __init__(self, master):
self.master = master
self.frame = tk.Frame(self.master)
self.frame.pack()
self.kill = tk.Button(self.frame, text = 'Kill', width = 25, command = self.close)
self.kill.pack()
self.displayimg = tk.Button(self.frame, text = 'Display', width = 25, command = lambda: show)
self.displayimg.pack()
def close(self):
self.master.destroy()
def show():
img = ImageTk.PhotoImage(im)
panel = Label(root, image=im)
panel.image = img
panel.place(x=0,y=0)