kosbie的python课程视频_用python 2绘制基本形状

这是一些Tkinter示例代码。请注意,据我所知,Tkinter不支持透明性;但它可以通过点画来伪造透明性,如下所示:# copied from http://www.kosbie.net/cmu/fall-10/15-110/koz/misc-demos/src/semi-transparent-stipple-demo.py

# semi-transparent-stipple-demo.py

# note: stipple only works for some objects (like rectangles)

# and not others (like ovals). But it's better than nothing...

from Tkinter import *

def redrawAll(canvas):

canvas.delete(ALL)

# draw a red rectangle on the left half

canvas.create_rectangle(0, 0, 250, 600, fill="red")

# draw semi-transparent rectangles in the middle

canvas.create_rectangle(200, 75, 300, 125, fill="blue", stipple="")

canvas.create_rectangle(200, 175, 300, 225, fill="blue", stipple="gray75")

canvas.create_rectangle(200, 275, 300, 325, fill="blue", stipple="gray50")

canvas.create_rectangle(200, 375, 300, 425, fill="blue", stipple="gray25")

canvas.create_rectangle(200, 475, 300, 525, fill="blue", stipple="gray12")

def init(canvas):

redrawAll(canvas)

########### copy-paste below here ###########

def run():

# create the root and the canvas

root = Tk()

canvas = Canvas(root, width=500, height=600)

canvas.pack()

# Store canvas in root and in canvas itself for callbacks

root.canvas = canvas.canvas = canvas

# Set up canvas data and call init

canvas.data = { }

init(canvas)

# set up events

# root.bind("", mousePressed)

# root.bind("", keyPressed)

# timerFired(canvas)

# and launch the app

root.mainloop() # This call BLOCKS (so your program waits until you close the window!)

run()

会产生一些

XrUW3.gif

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值