OS X中的tkinter点画选项行为不当

时间:2016-03-14 18:13:38

标签: python macos tkinter

我正在运行此示例code以在Windows和OS X上测试stipple但结果却不同。发生了什么事?

Windows vs. OS X

# 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()

1 个答案:

答案 0 :(得分:2)

据我所知,点画从未在OSX上发挥作用 - 它可能在OS9下有效,但就在2011年,这个问题已被讨论并标记为“关闭,不会修复”#34;在OSX Tk stipple ticket discussion for 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中不起作用的问题!