【问题标题】:Display IMAGE and TEXTBOX simultanously in a "form" with PYTHON使用 PYTHON 以“形式”同时显示 IMAGE 和 TEXT BOX
【发布时间】:2018-11-21 08:03:11
【问题描述】:

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

【问题讨论】:

    标签: python image opencv tkinter textbox


    【解决方案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()
    

    【讨论】:

    • 顺便问一下,有什么方法可以将图片和文本框分开吗?谢谢!
    • 您的意思是有两个窗口:一个用于图像,另一个用于文本,或者您想要一个透明的文本框,通过它可以看到背景
    • 我的意思是一个窗口 - 顶部的图像和窗口底部的文本框,因此我可以输入图像信息
    【解决方案2】:

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

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

    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

    【讨论】:

      猜你喜欢
      • 2016-12-16
      • 2019-12-02
      • 1970-01-01
      • 2011-08-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-02-19
      • 2022-06-30
      相关资源
      最近更新 更多