相关疑难解决方法(0)

有没有办法在tkinter.ttk.Notebook中为标签添加关闭按钮?

我想为每个标签添加关闭按钮tkinter.ttk.Notebook.我已经尝试添加图像并对点击事件做出反应,但遗憾的BitmapImage是没有bind()方法.

我该如何修复此代码?

#!/usr/binenv python3

from tkinter import *
from tkinter.ttk import *


class Application(Tk):
    def __init__(self):
        super().__init__()
        notebook = Notebook(self)
        notebook.pack(fill=BOTH, expand=True)
        self.img = BitmapImage(master=self, file='./image.xbm')
        self.img.bind('<Button-1>', self._on_click)
        notebook.add(Label(notebook, text='tab content'), text='tab caption', image=self.img)

    def _on_click(self, event):
        print('it works')

app = Application()
app.mainloop()
Run Code Online (Sandbox Code Playgroud)

image.xbm

#define bullet_width 11
#define bullet_height 9
static char bullet_bits = {
    0x00, 0x00, 0x00, 0x00, 0x78, 0x00, 0xf8, 0x00, 0xf8, 0x00, 0xf8, 0x00, 0x70, 0x00, 0x00, 0x00, 0x00, 0x00
}
Run Code Online (Sandbox Code Playgroud)

python tkinter

1
推荐指数
1
解决办法
3191
查看次数

标签 统计

python ×1

tkinter ×1