简体   繁体   中英

How can I close a notebook tab in tkinter?

The question is:

How can I close the tabs in tkinter.ttk Notebook widget? To make things simple,

def add_tab():
    global tab
    tab = Frame(notebook)
    notebook.add(tab, text=f'{"new.txt": ^20}')

def close_tab():
    tab.destroy()

However, when I execute this, the tab that is created most recently gets closed. The others do not get closed even when I click the button.

Moreover, how can I find which tab is currently opened and close that accordingly?

Is there a solution to this problem?

You can use notebook.forget("current") to remove the current selected tab:

def close_tab():
    notebook.forget("current")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM