【发布时间】:2018-05-15 14:08:43
【问题描述】:
我的项目是关于加载图像,当我点击一个按钮时,图像中会出现一个文本区域,我可以在上面写一个文本,然后保存写在图像和图像上的文本。为此,我使用了tkinter,但我将图像设置为背景并添加了一个文本框(text widget)并输入了文本,但显然我无法保存该图像(设置为背景的图像)和文本写在上面。我尝试使用PIL,但没有找到我想要的东西。
这是我使用tkinter 的代码:
from tkinter import *
from PIL import ImageTk
import cv2
#root = Tk()
image=cv2.imread("New_refImg.png")
width_1, height_1,channels = image.shape
print(width_1)
print(height_1)
canvas = Canvas(width =height_1, height = width_1, bg = 'blue')
canvas.pack(expand = 1, fill = BOTH)
img = ImageTk.PhotoImage(file = "New_refImg.png")
canvas.create_image(0, 0, image = img, anchor = NW)
#Add text
entry = Entry(canvas, width=12)
entry.pack(side=BOTTOM,padx=43,pady=height_1-130) # "side" position button
def onok():
x= entry.get().split('x')
print(x)
Button(canvas, text='OK', command=onok).pack(side=LEFT)
mainloop()
【问题讨论】:
标签: python-3.x image python-imaging-library tkinter-canvas