Python User Input and Interaction
Main.PythonWidgets History
Hide minor edits - Show changes to markup
(: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:)
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.
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.
(:title Python User Input and Interactive Displays:)
(:title Python User Input and Interaction:)
(:title Python User Interaction:)
(:title Python User Input and Interactive Displays:)
display(name,age)
display(myName,myAge)
print(name.value + ' is ' + str(age.value) + ' years old')
print(myName.value + ' is ' + str(myAge.value) + ' years old')
Widgets are another type of input device for IPython notebooks.
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:)
(:source lang=python")
(:source lang=python:)
(:source lang=python")
(:source lang=python:)
<iframe width="560" height="315" src="https://www.youtube.com/embed/6SHnmho7zCs" frameborder="0" allowfullscreen></iframe>
(: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:)