ttk标签widg中的多个图像

2024-09-23 22:21:10 发布

您现在位置:Python中文网/ 问答频道 /正文

使用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


Tags: fromimporttkinterstatic标签widthonebits
1条回答
网友
1楼 · 发布于 2024-09-23 22:21:10

我发现文档有点混乱,但看起来您想要的是'hover',而不是'active'。你知道吗

我不知道任何来源解释哪些状态标志是自动设置在哪个wigdet在哪个条件。我在这里做的是将鼠标光标放在标签上,然后通过调用label.state()查询状态。你知道吗

相关问题 更多 >