之前一直想知道如何快速通过整型变量生成颜色文本,直到问了chatgpt,下面是生成红颜色的一个实例:
r = 255 g = 0 b = 0 color = '#%02x%02x%02x' % (r, g, b)
展示颜色的实例程序:
from tkinter import * r = Tk() c = Canvas(r) c.pack(fill=BOTH, expand=True) b = Button(r, text='start', command=lambda: c.create_rectangle(0, 0, c.winfo_width(), c.winfo_height(), fill='#%02x%02x%02x' % (255, 0, 0))) b.pack(fill=X) r.mainloop()
标签:高效,02x%,颜色,Python,winfo,生成,文本,fill From: https://www.cnblogs.com/roundfish/p/17788124.html