Python Forum
Thread Rating:
  • 2 Vote(s) - 3 Average
  • 1
  • 2
  • 3
  • 4
  • 5
add a textbox in an image
#1
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
Reply
#2
Yes.
Reply
#3
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
Reply
#4
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
Reply
#5
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.
Reply
#6
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

Reply
#7
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.
Reply
#8
https://stackoverflow.com/a/16377244/4046632
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#9
@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.
Reply
#10
it clearly shows how to add the text to image. it's an example of how to use what @woooee suggested
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Take particular symbol from textbox help samuelbachorik 3 2,202 Apr-14-2020, 03:55 AM
Last Post: steve_shambles
  Print func textbox instead of shell zykbee 1 5,282 Dec-06-2017, 08:22 PM
Last Post: nilamo
  matplotlib textbox kiyoshi7 3 6,086 Oct-21-2017, 10:57 PM
Last Post: kiyoshi7

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020