【发布时间】:2020-03-03 20:34:11
【问题描述】:
我正在尝试启用检测,选择了哪个选项卡。在返回选择的选项卡时,“添加”按钮将打开相应的窗口。
我有一个带有 if 语句的单独函数,以确保单击按钮将打开相应的窗口。但是,它不像我希望的那样工作。
无论选择哪个选项卡,它都会打开 3 个选项卡中的 2 个。
功能代码如下:
def tab_add_btn():
if tab_parent.index(active_business):
nieuwe_zaken.business()
if tab_parent.index(noc):
noc_info.add_noc_info()
if tab_parent.index(caller):
Form.add_caller()
该应用正在从项目中的不同 .py 文件调用其他窗口。
无论打开哪个选项卡,每次单击按钮时都会打开 add_noc_info 和 add_caller 函数。即使我想打开打开的标签对应的功能。
我尝试了几种不同的语句/函数,但都没有成功。
# The function which is called by the button
def tab_add_btn():
if tab_parent.index(active_business):
nieuwe_zaken.business()
if tab_parent.index(noc):
noc_info.add_info()
if tab_parent.index(caller):
Form.add_caller()
# The button
add = ttk.Button(main_window, text = "Add", command = tab_add_btn)
add.place(x = 1093, y = 495)
我希望按钮根据打开/选择的选项卡打开相应的窗口(功能)。
如果你们需要更多代码 sn-ps,请告诉我。
提前致谢!
【问题讨论】:
-
<notebook ref>.index(tabid)被定义为“返回tabid指定的tab的数字索引”,因此all你的if tab_parent.index(...总是True。你的意思是.select(),它“返回当前选定窗格的小部件名称。”
标签: python user-interface button tkinter