python : html 调用本地python程序

13 篇文章 0 订阅

show_python.html

<!DOCTYPE html>
<html>
  <head>
    <meta charset="gb2312">
    <title>python draw flowers</title>
<script language="javascript">   
function exec1 (command) {   
  var ws = new ActiveXObject("WScript.Shell");   
  ws.exec(command);   
}   
</script> 
  </head>
  <body>
    turtle 画一朵花    <a href="/python/draw_flower1.py" target="show"> 源代码 </a>  
    <input type="button" value="运行 python" onclick="exec1('D:\\python27\\pythonw.exe D:/python/draw_flower1.py')" />
    <br/>
    turtle 画一朵玫瑰花 <a href="/python/draw_rose1.py" target="show"> 源代码 </a>  
    <input type="button" value="运行 python" onclick="exec1('D:\\python27\\pythonw.exe D:/python/draw_rose1.py')" />
    <br/>
    turtle 画一朵西兰花 <a href="/python/draw_xilan1.py" target="show"> 源代码 </a>  
    <input type="button" value="运行 python" onclick="exec1('D:\\python27\\pythonw.exe D:/python/draw_xilan1.py')" />
    <br/>
    <iframe name="show" id="show" width="800" height="500"/>    
  </body>
</html>

draw_flower1.py 见:python : turtle 画一朵花

draw_rose1.py

# -*- coding: cp936 -*-
import turtle

window = turtle.Screen()
window.bgcolor("white")
window.title("draw a rose")

tt = turtle.Turtle()
# 设置初始位置
tt.penup()
tt.left(90)
tt.fd(200)
tt.pendown()
tt.right(90)

# 花蕊
tt.fillcolor("red")
tt.begin_fill()
tt.circle(10,180)
tt.circle(25,110)
tt.left(50)
tt.circle(60,45)
tt.circle(20,170)
tt.right(24)
tt.fd(30)
tt.left(10)
tt.circle(30,110)
tt.fd(20)
tt.left(40)
tt.circle(90,70)
tt.circle(30,150)
tt.right(30)
tt.fd(15)
tt.circle(80,90)
tt.left(15)
tt.fd(45)
tt.right(165)
tt.fd(20)
tt.left(155)
tt.circle(150,80)
tt.left(50)
tt.circle(150,90)
tt.end_fill()
 
# 花瓣1
tt.left(150)
tt.circle(-90,70)
tt.left(20)
tt.circle(75,105)
tt.setheading(60)
tt.circle(80,98)
tt.circle(-90,40)

# 花瓣2
tt.left(180)
tt.circle(90,40)
tt.circle(-80,98)
tt.setheading(-83)

# 叶子1
tt.fd(30)
tt.left(90)
tt.fd(25)
tt.left(45)
tt.fillcolor("green")
tt.begin_fill()
tt.circle(-80,90)
tt.right(90)
tt.circle(-80,90)
tt.end_fill()
 
tt.right(135)
tt.fd(60)
tt.left(180)
tt.fd(85)
tt.left(90)
tt.fd(80)
 
# 叶子2
tt.right(90)
tt.right(45)
tt.fillcolor("green")
tt.begin_fill()
tt.circle(80,90)
tt.left(90)
tt.circle(80,90)
tt.end_fill()
 
tt.left(135)
tt.fd(60)
tt.left(180)
tt.fd(60)
tt.right(90)
tt.circle(200,60)
tt.ht() # hideturtle
window.exitonclick()

draw_xilan1.py

# -*- coding: cp936 -*-
# Turtle 绘制一棵西兰花
# 绘制一棵西兰花,从主干出发以一定的角度向左向右生成对称的枝干,
# 再从每个枝干出发向左向右生成对称的枝干,循环此动作,
# 并最终绘制出一棵漂亮的西兰花。
import turtle

window = turtle.Screen()
window.bgcolor("white")
window.title(u"draw 西兰花")

def tree(plist,l,a,f):
    if l>5:
        lst=[]
        for p in plist:
            p.forward(l)
            q = p.clone()
            p.left(a)
            q.right(a)
            lst.append(p)
            lst.append(q)
        tree(lst,l*f,a,f)

def maketree(x,y,clr):
    p = turtle.Turtle()
    p.pensize(5)
    p.color(clr)
    p.hideturtle()
    p.getscreen().tracer(30,0)
    #p.speed(10)
    p.left(90)
    p.penup()
    p.goto(x,y)
    p.pendown()
    t=tree([p],200,20,0.6375)
    #print(len(p.getscreen().turtles()))

def main():
    maketree(0,-300,"green")

main()
window.exitonclick()

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值