Python Tkinter 点画圆弧
Python Tkinter Stippling an arc
我正在尝试使用 python 在 Tkinter 中制作国际象棋游戏。对于碎片上的阴影,我打算使用点画,但是,虽然点画图案出现在其中一个形状上,但它不适用于弧形。这是相关代码:
from Tkinter import *
master = Tk()
win = Canvas(master, width=800, height=800)
def draw(x, y): #draws a pawn
win.create_oval(x-15, y-40, x+15, y-10, fill="#FFFFFF") #head
win.create_arc(x-15, y-40, x+15, y-10, style=CHORD, start=225, extent=135, stipple="gray25") #head shading (not appearing stippled)
win.create_polygon(x+8, y-12, x-8, y-12, x-15, y-5, x-10, y-5, x-20, y+30, x-30, y+35, x-30, y+40, x+30, y+40, x+30, y+35, x+20, y+30, x+10, y-5, x+15, y-5, fill="#FFFFFF", outline="black") #body
win.create_polygon(x-10, y-5, x+10, y-5, x+15, y+15, stipple="gray25") #body shading (appearing stippled)
win.pack()
master.update()
draw(400, 400)
如有任何帮助,我们将不胜感激。
看起来这在大多数 Tkinter 版本中是不可能直接实现的,至少在 Windows 平台上是这样。
发件人:http://www.scoberlin.de/content/media/http/informatik/tkinter/x3009-options.htm
在"Oval options"之下:
"As of Tk 8.0, the stipple option is ignored on the Windows platform.
To draw stippled ovals, you have to create corresponding polygons."
如果这不是您的情况,文档中还有一条注释说明您需要指定填充以点画 oval/arc/chord
无论如何,近似弦的多边形都可以。 . .尽管这样做似乎很痛苦。
我正在尝试使用 python 在 Tkinter 中制作国际象棋游戏。对于碎片上的阴影,我打算使用点画,但是,虽然点画图案出现在其中一个形状上,但它不适用于弧形。这是相关代码:
from Tkinter import *
master = Tk()
win = Canvas(master, width=800, height=800)
def draw(x, y): #draws a pawn
win.create_oval(x-15, y-40, x+15, y-10, fill="#FFFFFF") #head
win.create_arc(x-15, y-40, x+15, y-10, style=CHORD, start=225, extent=135, stipple="gray25") #head shading (not appearing stippled)
win.create_polygon(x+8, y-12, x-8, y-12, x-15, y-5, x-10, y-5, x-20, y+30, x-30, y+35, x-30, y+40, x+30, y+40, x+30, y+35, x+20, y+30, x+10, y-5, x+15, y-5, fill="#FFFFFF", outline="black") #body
win.create_polygon(x-10, y-5, x+10, y-5, x+15, y+15, stipple="gray25") #body shading (appearing stippled)
win.pack()
master.update()
draw(400, 400)
如有任何帮助,我们将不胜感激。
看起来这在大多数 Tkinter 版本中是不可能直接实现的,至少在 Windows 平台上是这样。
发件人:http://www.scoberlin.de/content/media/http/informatik/tkinter/x3009-options.htm
在"Oval options"之下:
"As of Tk 8.0, the stipple option is ignored on the Windows platform. To draw stippled ovals, you have to create corresponding polygons."
如果这不是您的情况,文档中还有一条注释说明您需要指定填充以点画 oval/arc/chord
无论如何,近似弦的多边形都可以。 . .尽管这样做似乎很痛苦。