我想问一下是否有一种有效的方法(任何数学算法,内置函数)在假设椭圆形之间放置垂直“ strip ”。这是我想放置 strip 的示例代码
from tkinter import *
painting = Canvas(root, width = 120, height = 160).pack()
painting.create_oval(35,70,85,90, outline = "red",width =3)
最佳答案
您可以通过创建自己的 .xbm 位图文件(参见 1)并将其传递给 stipple
选项(参见 2)来使用自定义填充图案。
示例代码:
import tkinter as tk
class Application(tk.Frame):
def __init__(self, master=None):
tk.Frame.__init__(self, master)
self.createWidgets()
self.pack()
def createWidgets(self):
self.painting = tk.Canvas(self, width=120, height=160)
self.painting.create_oval(35, 70, 85, 90, outline="red", width=3, stipple='@/tmp/stripes.xbm', fill='red')
self.painting.pack()
root = tk.Tk()
app = Application(master=root)
app.mainloop()
/tmp/stripes.xbm
的内容:
#define stripes_width 8
#define stripes_height 1
static unsigned char stripes_bits[] = {
0x07 };
0x07
= 00000111
是 8 个像素的二进制表示。颜色由 fill
选项指定。
结果:
关于python - 如何使用 tkinter 在几何条纹之间制作条纹线?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35495523/