-3

The below code is a section of my code which is supposed to be a stock management system. I have encountered several problems which i would appreciate any help for.

from tkinter import*
from tkinter import Tk, StringVar, ttk
#-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------#
import random
import datetime


import time;
import csv
opencsv=open('RED.csv','a')
Data=[]

LH=Label(LowerHeading, font=('arial',12,'bold'), text ="Update", bd = 10, width = 15, anchor = 'w')
LH.grid(row=1,column=0)

#-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------#
start.mainloop()

I Would like to add an image so for example if IDO1 is clicked by the user an image of a dress would be shown

The link didn't address my problem. I gained an error that said NO module named PIL

1 Answers1

0

You can have a look into PhotoImage Class.

Inserting images is simple.

import Tkinter as tk
from PIL import ImageTk, Image

path = 'C:/xxxx/xxxx.jpg'

root = tk.Tk()
img = ImageTk.PhotoImage(Image.open(path))
panel = tk.Label(root, image = img)
panel.pack(side = "bottom", fill = "both", expand = "yes")
root.mainloop()

Hope this helps.

Do have a look at Using Images in Labels section of Tkinter Labels page.

You can read Tkinter's PhotoImage and Label widgets for customizations.

UPDATE - For installing 'PIL' from pillow -

PIL is from package pillow. use -

sudo pip install pillow

Then from PIL import ImageTk will not give errors.

If pip is not installed then install it by using-

sudo apt-get install python-pip 
pro_cheats
  • 1,534
  • 1
  • 15
  • 25