使用ttk标签,可以指定根据标签状态显示的多个图像。但我不能让它工作。这是密码。你知道吗
from tkinter import *
from tkinter.ttk import *
BITMAP0 = """
#define zero_width 24
#define zero_height 32
static char zero_bits[] = {
0x00,0x00,0x00, 0x00,0x00,0x00, 0xf0,0x3c,0x0f, 0xf0,0x3c,0x0f,
0xf0,0x3c,0x0f, 0xf0,0x3c,0x0f, 0x00,0x00,0x00, 0x00,0x00,0x00,
0xf0,0x00,0x0f, 0xf0,0x00,0x0f, 0xf0,0x00,0x0f, 0xf0,0x00,0x0f,
0x00,0x00,0x00, 0x00,0x00,0x00, 0xf0,0x00,0x0f, 0xf0,0x00,0x0f,
0xf0,0x00,0x0f, 0xf0,0x00,0x0f, 0x00,0x00,0x00, 0x00,0x00,0x00,
0xf0,0x00,0x0f, 0xf0,0x00,0x0f, 0xf0,0x00,0x0f, 0xf0,0x00,0x0f,
0x00,0x00,0x00, 0x00,0x00,0x00, 0xf0,0x3c,0x0f, 0xf0,0x3c,0x0f,
0xf0,0x3c,0x0f, 0xf0,0x3c,0x0f, 0x00,0x00,0x00, 0x00,0x00,0x00
};
"""
BITMAP1 = """
#define one_width 24
#define one_height 32
static char one_bits[] = {
0x00,0x00,0x00, 0x00,0x00,0x00, 0x00,0x00,0x0f, 0x00,0x00,0x0f,
0x00,0x00,0x0f, 0x00,0x00,0x0f, 0x00,0x00,0x00, 0x00,0x00,0x00,
0x00,0x00,0x0f, 0x00,0x00,0x0f, 0x00,0x00,0x0f, 0x00,0x00,0x0f,
0x00,0x00,0x00, 0x00,0x00,0x00, 0x00,0x00,0x0f, 0x00,0x00,0x0f,
0x00,0x00,0x0f, 0x00,0x00,0x0f, 0x00,0x00,0x00, 0x00,0x00,0x00,
0x00,0x00,0x0f, 0x00,0x00,0x0f, 0x00,0x00,0x0f, 0x00,0x00,0x0f,
0x00,0x00,0x00, 0x00,0x00,0x00, 0x00,0x00,0x0f, 0x00,0x00,0x0f,
0x00,0x00,0x0f, 0x00,0x00,0x0f, 0x00,0x00,0x00, 0x00,0x00,0x00
};
"""
root = Tk()
img0 = BitmapImage(data=BITMAP0, foreground='lime', background='black')
img1 = BitmapImage(data=BITMAP1, foreground='lime', background='black')
label = Label(root, image=(img0, 'active', img1))
label.pack()
当鼠标移过标签时,标签是“活动”的。所以当鼠标经过时,显示的数字应该从0切换到1。但它不起作用。 有什么帮助吗? Python 3.5.1/Windows Vista
我发现文档有点混乱,但看起来您想要的是
'hover'
,而不是'active'
。你知道吗我不知道任何来源解释哪些状态标志是自动设置在哪个wigdet在哪个条件。我在这里做的是将鼠标光标放在标签上,然后通过调用
label.state()
查询状态。你知道吗相关问题 更多 >
编程相关推荐