Попробуйте так:
import tkinter as tk
from tkinter import ttk
win = tk.Tk()
def oncontextaction(event):
name_of_x_y = nb.identify(event.x, event.y)
if name_of_x_y:
x = event.x
if 10 <= x < 177 :
index = 0
print(f'ПКМ: {nb.tab(index)["text"]}; index = {index}') #
if 177 <= x < 342 :
index = 1
print(f'ПКМ: {nb.tab(index)["text"]}; index = {index}')
if 342 <= x < 508 :
index = 2
print(f'ПКМ: {nb.tab(index)["text"]}; index = {index}')
color='#21252b'
win.configure(background = color)
win.resizable(False, False)
sky_color = "sky blue"
gold_color = "gold"
color_tab = "#ccdee0"
#style
style = ttk.Style()
style.theme_create( "beautiful", parent = "alt", settings ={
"TNotebook": {
"configure": {"tabmargins": [10, 10, 20, 10], "background":sky_color }},
"TNotebook.Tab": {
"configure": {"padding": [30, 15],
"background": sky_color,
"font":('consolas italic', 14),
"width": 10,
"borderwidth":[3]},
"map": {"background": [("selected", gold_color), ('!active', sky_color), ('active', color_tab)],
"expand": [("selected", [1, 1, 1, 0])]}}})
style.theme_use("beautiful")
style.layout("Tab",
[('Notebook.tab', {'sticky': 'nswe', 'children':
[('Notebook.padding', {'side': 'top', 'sticky': 'nswe', 'children':
#[('Notebook.focus', {'side': 'top', 'sticky': 'nswe', 'children':
[('Notebook.label', {'side': 'top', 'sticky': ''})],
#})],
})],
})]
)
style.configure('TLabel', background = color , foreground = 'white')
style.configure('TFrame', background = color)
nb = ttk.Notebook(win, width=300, height=300)
fr1 = ttk.Frame(nb)
fr2 = ttk.Frame(nb)
fr3 = ttk.Frame(nb)
lb1 = ttk.Label(fr1, text="Tab1")
lb2 = ttk.Label(fr2, text="Tab2")
lb3 = ttk.Label(fr3, text="Tab3")
lb1.pack(padx=5, pady=5)
lb2.pack(padx=5, pady=5)
lb3.pack(padx=5, pady=5)
fr1.pack(padx=5, pady=5)
fr2.pack(padx=5, pady=5)
fr3.pack(padx=5, pady=5)
nb.add(fr1, text="Some 1111111")
nb.add(fr2, text="Some 2")
nb.add(fr3, text="Some 3")
nb.pack(fill="both", expand=1, padx=5, pady=5)
nb.enable_traversal()
nb.bind("<Button-3>", oncontextaction)
win.mainloop()
