[英]How can I close a notebook tab in tkinter?
The question is:问题是:
How can I close the tabs in tkinter.ttk Notebook
widget?如何关闭 tkinter.ttk Notebook
小部件中的选项卡? 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:您可以使用notebook.forget("current")
删除当前选定的选项卡:
def close_tab():
notebook.forget("current")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.