1

Here what I'd like

I'm new in PYTHON. I'm trying to display IMAGE and TEXTBOX simultaneously in a "Form" with PYTHON.

My problem: Image is not visible on the screen. How to solve that problem?

Thanks,

My code:

import tkinter as tk
from PIL import ImageTk, Image

#This creates the main window of an application
window = tk.Tk()
window.title("SEE image and ENTER its information")
window.geometry("600x400")
window.configure(background='grey')

# Create textbox in window
text_widget = tk.Text(window)
text_widget.insert('insert',"Enter image information here")
text_widget.pack(anchor = "w", padx = 50, pady = 50)



#Creates a tkinter-compatible photo image.
path = "Picture.jpg"
img = ImageTk.PhotoImage(Image.open(path))

#The Label widget is a standard tkinter widget used to display a text or 
image on the screen.
panel = tk.Label(window, image = img)

#The Pack geometry manager packs widgets in rows or columns.
#panel.pack(side = "bottom", fill = "both", expand = "no")
panel.pack()


#Start the GUI
window.mainloop()
Bryan Oakley
  • 370,779
  • 53
  • 539
  • 685
Khanh Nguyen
  • 11
  • 1
  • 3

2 Answers2

1
import tkinter as tk
from PIL import ImageTk, Image

#This creates the main window of an application
window = tk.Tk()
window.title("SEE image and ENTER its information")
window.geometry("600x400")
window.configure(background='grey')

#Creates a tkinter-compatible photo image.
path = "Picture.jpg"
img = ImageTk.PhotoImage(Image.open(path))

#The Label widget is a standard tkinter widget used to display a text or image on the screen.
panel = tk.Label(window, image = img)

# Create textbox in window
text_widget = tk.Text(panel)
text_widget.insert('insert',"Enter image information here")
text_widget.pack(anchor = "w", padx = 50, pady = 50)


#The Pack geometry manager packs widgets in rows or columns.
#panel.pack(side = "bottom", fill = "both", expand = "no")
panel.pack()


#Start the GUI
window.mainloop()
Akhil
  • 369
  • 1
  • 5
  • 13
1

If that's the idea, do you wish to display information to the user or for user to enter information?

Assuming the latter, here is something.

import tkinter as tk
from PIL import ImageTk, Image

window = tk.Tk()
window.title("SEE image and ENTER its information")
window.geometry("600x400") # You can drop this line if you want.
window.configure(background='grey')

path = "Picture.jpg"
img = ImageTk.PhotoImage(Image.open(path))
panel = tk.Label(window, image = img)

txtVar = tk.StringVar(None)
usrIn = tk.Entry(window, textvariable = txtVar, width = 90)
usrIn.grid(row = 50, column = 60)

usrIn.pack()
panel.pack()
window.mainloop()

ThetxtVar can be used for accepting info from user. You may also have to use the Button feature if needed. Here is nice link.

Akhil
  • 369
  • 1
  • 5
  • 13