我正在运行这个示例 code在 Windows 和 OS X 上测试 stipple 但结果不同。这是怎么回事?
# 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("<Button-1>", mousePressed)
# root.bind("<Key>", keyPressed)
# timerFired(canvas)
# and launch the app
root.mainloop() # This call BLOCKS (so your program waits until you close the window!)
run()
请您参考如下方法:
据我所知,点画从未在 OSX 上起作用——它可能在 OS9 下起作用,但就在 2011 年,这个问题在 OSX Tk stipple ticket discussion 中被讨论并标记为“已关闭,不会修复”。对于 Tk 8.5
如果您查看 Tk 8.6 的当前资源,情况看起来仍然很严峻:
void *
TkMacOSXMakeStippleMap(
Drawable drawable, /* Window to apply stipple. */
Drawable stipple) /* The stipple pattern. */
{
return NULL;
}
虽然我看过其他Tk sources where this function is defined , 我无法判断它们是否对应于任何官方发布。
这不仅仅是在 OSX 中实现点画的问题,他们似乎只是简单地记录点画在 OSX 中不起作用的问题!
