如何在 ttk 笔记本中创建 'n' 个标签页? n 是一个变量(用户输入)

How do I create 'n' tabs in ttk notebook? n is a variable(user-input)

我接受了用户的数字 n,我想显示 n 个包含某些信息的标签,我该怎么做?

import tkinter as tk                     
from tkinter import ttk 

root = tk.Tk() 
tabControl = ttk.Notebook(root) 

tab1 = ttk.Frame(tabControl) 
tab2 = ttk.Frame(tabControl) 

tabControl.add(tab1, text ='Tab 1') 
tabControl.add(tab2, text ='Tab 2') 
tabControl.pack(expand = 1, fill ="both") # i want to make n such tabs

ttk.Label(tab1, text ="some info here").grid(column = 0, row = 0) 
ttk.Label(tab2, text ="more info here").grid(column = 0, row = 0) 

root.mainloop() 

也许试试这个:

n = int(input("How many Tabs do you want to open?"))
tabs = []
for i in range(n):
    tabs.append(ttk.Frame(tabControl))

for i, tab in enumerate(tabs):
    tabControl.add(tab, text=f"Tab {str(i+1)}")

然后您可以通过遍历选项卡列表来编辑每个选项卡。