我一直在玩TKinter试图创建一个多选项卡窗口.
当我尝试的风格TNotebook.Tab它忽略了选项background和borderwidth,但它承认foreground.我究竟做错了什么?
以下是代码的相关部分:
COLOR_1 = 'black'
COLOR_2 = 'white'
COLOR_3 = 'red'
COLOR_4 = '#2E2E2E'
COLOR_5 = '#8A4B08'
COLOR_6 = '#DF7401'
#Notebook Style
noteStyler = ttk.Style()
noteStyler.configure("TNotebook", background=COLOR_1, borderwidth=0)
noteStyler.configure("TNotebook.Tab", background=COLOR_1, foreground=COLOR_3, lightcolor=COLOR_6, borderwidth=0)
noteStyler.configure("TFrame", background=COLOR_1, foreground=COLOR_2, borderwidth=0)
#Create Notebook and Tabs
note = ttk.Notebook(gui, style='TNotebook')
myTab = ttk.Frame(note, style='TFrame')
note.add(myTab, text = 'MyTab', compound=tk.TOP)
note.pack(anchor=tk.W)
Run Code Online (Sandbox Code Playgroud)
这是窗口的图像:

如果它很重要,我在Windows 7 64位上运行python 2.7.
我想为每个标签添加关闭按钮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)