Issue
I am trying to increase the width of the user input box generated by the interact
function from ipywidgets
.
My objective is that a user should be able to change the contents of the string using the interactive box, however I am unable to figure out how to do so.
import re
from ipywidgets import interact
x1 = """The Supreme Court, in the matter of, held that moratorium mentioned in section 141 Chapter XVII of the Act. / उच्चतम न्यायालय ने
Dwarkadhish Sakhar Karkhana Ltd. Vs. Pankaj Joshi and Anr. / द्वारकाधीश
Kalpraj Dharamshi & Anr. Vs. Kotak Investment Advisors Ltd. & Anr. / कल्पराज"""
# remove all non-english characters
x2 = re.sub(r'[^\x00-\x7f]',r'', x1)
def f(x):
return x
w = interact(f, x=x2)
(Width of the image showing the output reduced for ease of viewing)
However I want the input box to be much larger so that the user can make a change anywhere in the string using the box itself and that value is stored.
Any help will be appreciated.
Solution
This code is for a Python Jupyter notebook.
Insted of using interact
, use Textarea
:
import re
from ipywidgets import Layout, Textarea
x1 = """The Supreme Court, in the matter of, held that moratorium mentioned in section 141 Chapter XVII of the Act. / उच्चतम न्यायालय ने
Dwarkadhish Sakhar Karkhana Ltd. Vs. Pankaj Joshi and Anr. / द्वारकाधीश
Kalpraj Dharamshi & Anr. Vs. Kotak Investment Advisors Ltd. & Anr. / कल्पराज"""
# remove all non-english characters
x2 = re.sub(r'[^\x00-\x7f]',r'', x1)
w = Textarea(value=x2, layout=Layout(width='70%', height='100px'))
# Show widget
w
# Access widget value, even if you have changed the original text
w.value
Answered By - Enrique Pérez Herrero
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.