用PYTHON以“形式”同时显示IMAGE和TEXTBOX

时间:2018-06-12 02:24:01

标签: python image opencv tkinter textbox

Here what I'd like

我是PYTHON的新人。我正试图在PYTHON的“Form”中同时显示IMAGE和TEXTBOX。

我的问题:屏幕上看不到图像。如何解决这个问题?

谢谢,

我的代码:

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()

2 个答案:

答案 0 :(得分:0)

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()

答案 1 :(得分:0)

如果是这个想法,您是希望向用户显示信息还是让用户输入信息?

假设后者,这里有一些东西。

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()

txtVar可用于接受用户的信息。如果需要,您可能还必须使用Button功能。 这里很好link