如何使用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点阵显示器?
答案 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()