Отображение IMAGE и TEXTBOX одновременно в «форме» с PYTHON - PullRequest
0 голосов
/ 12 июня 2018

Вот что я хотел бы

Я новичок в PYTHON.Я пытаюсь отобразить IMAGE и TEXTBOX одновременно в «форме» с помощью PYTHON.

Моя проблема: изображение не отображается на экране.Как решить эту проблему?

Спасибо,

Мой код:

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 голосов
/ 14 июня 2018

Если это идея, хотите ли вы отображать информацию пользователю или пользователю вводить информацию?

Если предположить последнее, вот что.

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, если это необходимо.Вот хорошая ссылка .

0 голосов
/ 12 июня 2018
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()
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...