I am trying to make something like an image viewer. I call a method to load the next image into the UI. The space (grid) is still taken, everything doesn't collapse but the image is not shown. Does anyone know what could be the reason?
from tkinter import *
from PIL import Image, ImageTk
import glob
import os
root = Tk(className='logo classify')
def draw_image(i):
fNem = filenames[i]
image_ = Image.open(fNem)
x , y = image_.size
image_ = image_.reduce(factor=3, box=(0, 1000, x , y))
tkImage = ImageTk.PhotoImage(image_)
global imagelabel1
imagelabel1.grid_forget()
imagelabel1 = Label(image=tkImage)
imagelabel1.grid(row = 0, column = 0, rowspan = 8)
def enter():
global i
i += 1
draw_image(i)
e1.get()
if e1.get() == '':
print('error no name')
e2.get()
e3.get()
e4.get()
i=0
myLabel1 = Label(root, text="company name for logo1")
myLabel2 = Label(root, text="company name for logo2")
myLabel3 = Label(root, text="company name for logo3")
myLabel4 = Label(root, text="company name for logo4")
myButton1 = Button(root, text = 'ENTER', command = enter)
e1 = Entry(root, width = 50, borderwidth = 3)
e2 = Entry(root, width = 50, borderwidth = 3)
e3 = Entry(root, width = 50, borderwidth = 3)
e4 = Entry(root, width = 50, borderwidth = 3)
myLabel1.grid(row = 1, column = 1)
myLabel2.grid(row = 2, column = 1)
myLabel3.grid(row = 3, column = 1)
myLabel4.grid(row = 4, column = 1)
e1.grid(row= 1, column = 2)
e2.grid(row= 2, column = 2)
e3.grid(row= 3, column = 2)
e4.grid(row= 4, column = 2)
myButton1.grid(row = 5, column = 2)
buffer_ = Label(root, text = ' ').grid(row = 6, column = 2)
filenames = []
for filename in glob.glob('./resources/logo_images/*.jpg'):
filenames.append(filename)
id = os.path.split(filename)[1]
fNem = filenames[0]
print('filename: ', fNem)
image_ = Image.open(fNem)
print(image_.size)
image_ = image_.reduce(factor=3, box=(0, 1000, 3008, 4112))
tkImage = ImageTk.PhotoImage(image_)
imagelabel1 = Label(root, image=tkImage)
imagelabel1.grid(row = 0, column = 0, rowspan = 8)
root.mainloop()
#save session csv
The important part (I guess) would be the functions enter(), (which gets activated from the button) and draw_image(), which gets activated in enter.
Thanks guys !