<!-- forked from bnmnetp/simpleskulpt.html --><!-- script to include a python skulpt within a web page: from http://www.skulpt.org/ --><html><head><scriptsrc="http://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"type="text/javascript"></script><scriptsrc="http://www.skulpt.org/static/skulpt.min.js"type="text/javascript"></script><scriptsrc="http://www.skulpt.org/static/skulpt-stdlib.js"type="text/javascript"></script></head><body><scripttype="text/javascript">// output functions are configurable. This one just appends some text// to a pre element.functionoutf(text){varmypre=document.getElementById("output");mypre.innerHTML=mypre.innerHTML+text;}functionbuiltinRead(x){if(Sk.builtinFiles===undefined||Sk.builtinFiles["files"][x]===undefined)throw"File not found: '"+x+"'";returnSk.builtinFiles["files"][x];}// Here's everything you need to run a python program in skulpt// grab the code from your textarea// get a reference to your pre element for output// configure the output function// call Sk.importMainWithBody()functionrunit(){varprog=document.getElementById("yourcode").value;varmypre=document.getElementById("output");mypre.innerHTML='';Sk.canvas="mycanvas";Sk.pre="output";Sk.configure({output:outf,read:builtinRead});try{eval(Sk.importMainWithBody("<stdin>",false,prog));}catch(e){alert(e.toString())}}</script><h3>Try This</h3><form><textareaid="yourcode"cols="40"rows="10">import turtle
t = turtle.Turtle()
t.forward(100)
print "Hello World"
</textarea><br/><buttontype="button"onclick="runit()">Run</button></form><preid="output"></pre><!-- If you want turtle graphics include a canvas --><canvasid="mycanvas"></mycanvas></body></html>
Comments (0)
HTTPSSSH
You can clone a snippet to your computer for local editing.
Learn more.