Python Forum

Full Version: add a textbox in an image
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
hey,

I need to add a text box in an image, and when I run the application, I should be able to write in that text box. Is that possible using python? Huh

Thank you
Yes.
Thank you for your help, but can you please be more precise! I mean which section of the document is helpful in my case!

Thank you
Start with getting *something* on the screen, and then slowly adapt it to fit your needs: https://docs.python.org/3/library/tkinte...ld-program
First, you have to choose which software package you want to use to display the image and create a textbox/listbox. You have a ways to go before you can even begin on this.
I'm working with python! the library is tkinter, but the thing is that I need to save the picture after adding to it a text( I don't want a text already written in the code and display it when I run the console).
For now, I used my picture as background and I added a text box to it.
This is my code:
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()
But it's not what I really need!
Do you have any idea what should I use instead or what should I do to make it better?

Thank you

Quote:I need to save the picture after adding to it a text
You did not add anything to the image, but instead simply display something over the image. PIL has an ImageDraw method, but I have never used it https://pillow.readthedocs.io/en/3.0.x/r...eDraw.html and have no idea how to embed anything.
@buran, thank you for the link, we seem to have the same project but he is having troubles with the font while I'm having troubles with adding the text box.
Thank you.
it clearly shows how to add the text to image. it's an example of how to use what @woooee suggested
Pages: 1 2