如何从点阵显示中绘制大写字母?

时间:2016-07-05 20:40:47

标签: python tkinter tkinter-canvas

如何使用python tkinter以大写模式绘制所有字母? 使用帆布多边形有用吗?对A

这样的事情
w = Canvas(master, width=canvas_width, height=canvas_height).pack()
points = [100,0, 0, 100, 200,100]
w.create_polygon(points, outline=python_green, fill='yellow', width=3)

如何使用python tkinter或其他库创建一个简单的led点阵显示器?

1 个答案:

答案 0 :(得分:1)

对于大写字母,您可以使用非常大的字体来写大写字母(我不明白为什么要绘制它们):

from tkinter import Tk, Canvas

master = Tk()
canvas = Canvas(master, bg="white", width=200, height=200)
canvas.pack()
canvas.create_text(50,50, text="A", fill="red", font="Arial 100")

master.mainloop()

对于led点阵显示器,您可以执行以下操作:

from tkinter import Tk, Canvas
import numpy as np

dot_matrix = np.array([[0,0,0,0,0,0,0],
                       [0,0,1,1,1,0,0],
                       [0,1,0,0,0,1,0],
                       [0,0,0,0,0,1,0],
                       [0,0,0,0,1,0,0],
                       [0,0,0,1,0,0,0],
                       [0,0,1,0,0,0,0],
                       [0,1,1,1,1,1,0],
                       [0,0,0,0,0,0,0]])

master = Tk()
canvas = Canvas(master, bg="black", width=200, height=200)
canvas.pack()

def display_matrix(matrix):
    h,l = matrix.shape
    for i in range(h):
        for j in range(l):
            if matrix[i,j]:
                canvas.create_oval(5 + 12*j , 5 + 12*i, 15 + 12*j, 15 + 12*i, fill="red")

display_matrix(dot_matrix)

master.mainloop()

enter image description here