I have a small problem with printing and displaying a text,precisely print the titles of the subtab. This code prints the title of the selected tab of a match tab, after clicking on the button. For example TAB 1 which is the title of the first Tab, so I already print "TAB 1" correctly". Everything is OK, all ok, beacause my output is "TAB1".
To do this I use this function:
if tabControl.tab("current", "text"):
global x
x=Label(window, text='TAB1 is printed correctly', background="white", font='Helvetica 16 bold', fg="orange")
x.place(x=888, y=156)
THE PROBLEM: The problem is when I would like to print the sub-tabs as well, that is a tabcontrol inserted in the main tabcontrol. I can print the title of the main tabcontrol tabs, but I cannot print the titles of the second tabcontrol tabs. The function shown above is useful and correct to print TAB1, TAB2 or TAB3, i.e. the current open tab, but I don't know how to print the Example1, Example2, etc subtabs
THE QUESTION: For example, how can I select Example 2 and print 'Example2 is printed correctly'? (Example 2 is the title of a tab of the second tabcontrol contained in the main tabcontrol). So he would like to select the "Example2" tab and print Example2 is printed correctly
Can you help me please?
Code:
from tkinter import *
from tkinter import ttk
import tkinter as tk
import tkinter.font as tkFont
window=Tk()
window.title("example")
window.attributes('-zoomed', True)
window.configure(bg='#f3f2f2')
tabControl = ttk.Notebook(window, style='Custom.TNotebook', width=700, height=320)
cronaca = ttk.Notebook(tabControl)
politica = ttk.Notebook(tabControl)
gossip = ttk.Notebook(tabControl)
tabControl.add(cronaca, text ='TAB 1')
tabControl.add(politica, text ='TAB 2')
tabControl.add(gossip, text ='TAB 3')
tabControl.place(x=1, y=1)
a = ttk.Frame(cronaca)
canvas = tk.Canvas(a)
scrollbar = ttk.Scrollbar(a, orient="vertical", command=canvas.yview)
scrollable_frame = ttk.Frame(canvas, width = 500, height = 500)
scrollable_frame.bind(
"<Configure>",
lambda e: canvas.configure(
scrollregion=canvas.bbox("all")
)
)
canvas.create_window((0, 0), window=scrollable_frame, anchor="nw")
canvas.configure(yscrollcommand=scrollbar.set)
a.pack()
cronaca.add(a, text="Example 1")
canvas.pack(side="left", fill="both", expand=True)
scrollbar.pack(side="right", fill="y")
b = ttk.Frame(cronaca)
cronaca.add(b, text="Example 2")
c = ttk.Frame(cronaca)
cronaca.add(c, text="Example 3")
d = ttk.Frame(cronaca)
cronaca.add(d, text="Example 4")
def function1():
x = tabControl.tab("current", "text")
print(x)
#GENERA
button2 = Button(window, text="Print", command=function1)
button2.pack()
button2.place(x=5, y=430)
window.mainloop()
