python - 使用 PYTHON 在 "form"中同时显示图像和文本框

标签 python image opencv tkinter textbox

Here what I'd like

我是 PYTHON 的新手。我正在尝试使用 PYTHON 在“表单”中同时显示 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()

最佳答案

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

关于python - 使用 PYTHON 在 "form"中同时显示图像和文本框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50808428/

相关文章:

python - 在 sklearn pipeline 中为模型实现自定义 .fit() 方法

python - 在 python 中添加二进制数需要帮助

html - 为什么选项卡菜单图像必须比菜单尺寸大?

jquery - 从所选图像中删除蓝色覆盖/突出显示

python - OpenCV 3.0 线迭代器

python - 在不知道键的情况下查找字典值的类型

python - 填充 NAs : Min of values in group

css - HTML 背景重复

c++ - 使用 OpenCV VideoCapture 读取视频文件

opencv - OpenCv中的线性代数