Python User Input and Interaction

Main.PythonWidgets History

Show minor edits - Show changes to output

June 21, 2020, at 04:03 AM by 136.36.211.159 -
Changed lines 41-59 from:
 
----

(:html:)
 <div id="disqus_thread"></div>
    <script type="text/javascript">
        /* * * CONFIGURATION VARIABLES: EDIT BEFORE PASTING INTO YOUR WEBPAGE * * */
        var disqus_shortname = 'apmonitor'; // required: replace example with your forum shortname

        /* * * DON'T EDIT BELOW THIS LINE * * */
        (function() {
            var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true;
            dsq.src = 'https://' + disqus_shortname + '.disqus.com/embed.js';
            (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
        })();
    </script>
    <noscript>Please enable JavaScript to view the <a href="https://disqus.com/?ref_noscript">comments powered by Disqus.</a></noscript>
    <a href="https://disqus.com" class="dsq-brlink">comments powered by <span class="logo-disqus">Disqus</span></a>
(:htmlend:)
to:
 
Changed line 22 from:
Widgets are another type of input device for IPython notebooks. The same Name and Age input is shown below with a more complete tutorial video.
to:
Widgets are another type of input device but only for IPython. The same Name and Age input is shown below with a more complete tutorial video that shows how to create an interactive plot.
Changed line 1 from:
(:title Python User Input and Interactive Displays:)
to:
(:title Python User Input and Interaction:)
Changed line 1 from:
(:title Python User Interaction:)
to:
(:title Python User Input and Interactive Displays:)
Changed lines 30-31 from:
display(name,age)
to:
display(myName,myAge)
Changed line 33 from:
print(name.value + ' is ' + str(age.value) + ' years old')
to:
print(myName.value + ' is ' + str(myAge.value) + ' years old')
Changed lines 22-34 from:
Widgets are another type of input device for IPython notebooks.
to:
Widgets are another type of input device for IPython notebooks. The same Name and Age input is shown below with a more complete tutorial video.

(:source lang=python:)
import ipywidgets as wg
from IPython.display import display

myName = wg.Text(value='Name')
myAge = wg.IntSlider(description='Age:')
display(name,age)

### new cell
print(name.value + ' is ' + str(age.value) + ' years old')
(:sourceend:)
Changed line 24 from:
Attach:download.png [[python_widget.zip|Download IPython Widget Notebook]]
to:
Attach:download.png [[Attach:python_widget.zip|Download IPython Widget Notebook]]
Added lines 23-24:

Attach:download.png [[python_widget.zip|Download IPython Widget Notebook]]
Changed line 7 from:
(:source lang=python")
to:
(:source lang=python:)
Changed line 14 from:
(:source lang=python")
to:
(:source lang=python:)
Deleted lines 23-24:

Changed line 25 from:
to:
<iframe width="560" height="315" src="https://www.youtube.com/embed/6SHnmho7zCs" frameborder="0" allowfullscreen></iframe>
Added lines 1-47:
(:title Python User Interaction:)
(:keywords widget, web form, input, interaction, IPython, notebook:)
(:description Introduction to user interaction in Python with examples on how to create a simple web-form and interactive plot.:)

User interaction is essential in many programs to select options and display results. An intuitive user interface is important to retrieve the right inputs and present results in an actionable format. A simple example of user input is an input dialog such as:

(:source lang=python")
myName = input('Name: ')
myAge = input('Age: ')
(:sourceend:)

The user inputs a name and age and Python stores those values in variables '''myName''' and '''myAge'''. It may be necessary to check the validity of the inputs with code such with a '''try''', '''except''' structure.

(:source lang=python")
myName = input('Name: ')
try:
  myAge = int(input('Age: '))
except:
  print 'Invalid age, please enter a number'
(:sourceend:)

Widgets are another type of input device for IPython notebooks.



(:html:)

(:htmlend:)
 
----

(:html:)
 <div id="disqus_thread"></div>
    <script type="text/javascript">
        /* * * CONFIGURATION VARIABLES: EDIT BEFORE PASTING INTO YOUR WEBPAGE * * */
        var disqus_shortname = 'apmonitor'; // required: replace example with your forum shortname

        /* * * DON'T EDIT BELOW THIS LINE * * */
        (function() {
            var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true;
            dsq.src = 'https://' + disqus_shortname + '.disqus.com/embed.js';
            (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
        })();
    </script>
    <noscript>Please enable JavaScript to view the <a href="https://disqus.com/?ref_noscript">comments powered by Disqus.</a></noscript>
    <a href="https://disqus.com" class="dsq-brlink">comments powered by <span class="logo-disqus">Disqus</span></a>
(:htmlend:)