我想准备键盘的图像,每个键可以被分配不同的颜色。我看过Python keyboardlayout包,但不清楚如何控制键的颜色。我更喜欢使用现有的Python包。
yc0p9oo01#
您可以使用update_key。例如,更改A键的颜色:
update_key
A
import tkinter as tk import tkinter.font as tkf import keyboardlayout as kl import keyboardlayout.tkinter as klt key_size = 60 window = tk.Tk() window.resizable(False, False) key_info_dict = { "margin": 5, #"color": "grey", letting color out so that it can be specified for each new key info profile "txt_color": "black", "txt_font": tkf.Font(family='Arial', size=key_size//4), "txt_padding": (key_size//6, key_size//10) } key_info = kl.KeyInfo(**key_info_dict, color="grey") keyboard_layout = klt.KeyboardLayout( kl.LayoutName.QWERTY, kl.KeyboardInfo(position=(0,0), padding=2), (key_size, key_size), # width, height, key_info, master=window ) key_info_red = kl.KeyInfo(**key_info_dict, color="red") keyboard_layout.update_key(key=kl.Key.A, key_info=key_info_red) window.mainloop()
输出:
1条答案
按热度按时间yc0p9oo01#
您可以使用
update_key
。例如,更改A
键的颜色:输出: