python - 如何使用 tkinter 在几何条纹之间制作条纹线?

标签 python tkinter

我想问一下是否有一种有效的方法(任何数学算法,内置函数)在假设椭圆形之间放置垂直“ strip ”。这是我想放置 strip 的示例代码

from tkinter import *  


painting = Canvas(root, width = 120, height = 160).pack()
painting.create_oval(35,70,85,90, outline = "red",width =3)

Visual example

Visual example

最佳答案

您可以通过创建自己的 .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 选项指定。

结果:

enter image description here

关于python - 如何使用 tkinter 在几何条纹之间制作条纹线?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35495523/

相关文章:

python - 我们如何获取长整数的用户输入?

python - 如何在 Python 中将一组字符串拆分为子字符串,使更短的子字符串更有可能?

Python 3.4.4 在 Tkinter 中设置参数?

python - Tkinter 麻烦 - 名称框架未定义

Python 类 : Inheritance vs Instantiation

Python 列表框

python - 使用 iloc 进行 Pandas 复制无法按预期工作

python - 使用接口(interface)/抽象基类是pythonic吗?

Python项目组织

python - 在两个 Tkinter 小部件之间拆分键盘输入