Issue
I’m building a command line application with python, and I Need to be able to print something, then the user edit it and return it to me
I know that Input() doesn’t fit to my case because the user can’t modify the text you give him. Is there a way to do it ?
Solution
I think that one way to do this is by using a keyboard input listener - this way you can figure out exactly what the user is doing (all characters being pressed, as well as backspace) and print the edited text.
You can have a look at this answer, which gives examples of how to achieve this in linux/windows: Key Listeners in python?.
If you are looking for a User Interface (not proper command line), you can use Tkinter do display a text box in which the user can input it's data.
An example (based on https://effbot.org/tkinterbook/entry.htm):
from Tkinter import *
master = Tk()
e = Entry(master, width=500)
e.pack()
e.focus_set()
def callback():
print e.get()
b = Button(master, text="get", width=50, command=callback)
b.pack()
mainloop()
Answered By - Ofer Arial
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.