我已经使用 tkinter 创建了一个 GUI,用于我的工作的应用程序部署程序。我的两个复选框有问题。我相信由于某种原因,我的“提交”按钮的逻辑变得混乱
我会详细说明...
仅选择“Kaseya(AzureAD)”复选框时,然后选择我的提交按钮,在我的日志中得到
2023-09-01 12:51:09,465 - 信息 - 当前选择的选项:[]
信息:main:当前选择的选项:[]
2023-09-01 12:51:09,466 - 信息 - 未选择任何选项。
信息:main:未选择任何选项。
当仅选择“趋势(AzureAD)”复选框时,然后选择我的提交按钮,在我的日志中我得到
2023-09-01 12:53:04,686 - 信息 - 当前选择的选项:['AzureAD']
信息:main:当前选择的选项:['AzureAD']
2023-09-01 12:53:04,687 - 信息 - AzureAD 的 Kaseya 复选框值:0
信息:main:AzureAD 的 Kaseya 复选框值:0
2023-09-01 12:53:04,687 - 信息 - AzureAD 的趋势复选框值:1
信息:main:AzureAD 的趋势复选框值:1
2023-09-01 12:53:04,687 - 信息 - 尝试安装 TrendMicro
信息:main:尝试安装 TrendMicro
错误:趋势:未连接到域。当前域 AzureAD FROM INSTALL_TREND()
“趋势(AzureAD)”复选框按预期工作,我有代码可以在按下“提交”按钮时记录两个活动复选框的值。感知“Kaseya(AzureAD)”复选框未按下= 0。
当选择两个复选框时,然后选择我的提交按钮,在我的日志中我得到
2023-09-01 12:54:32,387 - 信息 - 当前选择的选项:['AzureAD']
信息:main:当前选择的选项:['AzureAD']
2023-09-01 12:54:32,388 - 信息 - AzureAD 的 Kaseya 复选框值:1
信息:main:AzureAD 的 Kaseya 复选框值:1
2023-09-01 12:54:32,389 - 信息 - AzureAD 的趋势复选框值:1
信息:main:AzureAD 的趋势复选框值:1
2023-09-01 12:54:32,389 - 信息 - 尝试安装 TrendMicro
信息:main:尝试安装 TrendMicro
错误:趋势:未连接到域。当前域 AzureAD FROM INSTALL_TREND()
2023-09-01 12:54:32,390 - 信息 - 尝试安装 Kaseya
信息:main:尝试安装 Kaseya
错误:kaseya:未连接到域。当前域 AzureAD FROM INSTALL_KASEYA()
这也按预期运行,
没有意义的是为什么当我只选择“Kaseya(AzureAD)”时,它在复选框中没有值并且不起作用,但如果也选择了“trend(AzureAD)”复选框,它按预期工作。
也不要担心错误,(AzureAD) 不是我的安装功能的兼容域。其用于测试目的并且工作正常。
下面是我的“提交”按钮逻辑
def submit():
global browser_checkboxes, kaseya_checkboxes, trend_checkboxes
all_checkboxes = {**browser_checkboxes, **kaseya_checkboxes, **trend_checkboxes}
logger.info(f"All checkboxes: {all_checkboxes}")
selected_options = [option for option, var in all_checkboxes.items() if var.get() == 1]
logger.info(f"Browser checkboxes: {browser_checkboxes}")
logger.info(f"Kaseya checkboxes: {kaseya_checkboxes}")
logger.info(f"Trend checkboxes: {trend_checkboxes}")
# This line will log or print the selected options for debugging.
logger.info(f"Currently selected options: {selected_options}")
# checks if any Browser or Program has been selected to intall
if not selected_options:
logger.info("No options were selected.")
label.config(text="You have not selected any browsers or programs to install. Please select at least 1.")
return
# Check which Browsers to install and invoke the respective functions
if "Chrome" in selected_options:
logger.info("Attempting to install Chrome")
install_chrome()
if "Firefox" in selected_options:
logger.info("Attempting to install Firefox")
install_firefox()
# Setting Key
kaseya_key = f"Kaseya_{domain_name}"
kaseya_selected = kaseya_checkboxes.get(kaseya_key, {}).get() if kaseya_key in kaseya_checkboxes else None
trend_key = f"Trend_{domain_name}"
trend_selected = trend_checkboxes.get(trend_key, {}).get() if trend_key in trend_checkboxes else None
logger.info(f"Kaseya checkbox value for {kaseya_key}: {kaseya_selected}")
logger.info(f"Trend checkbox value for {trend_key}: {trend_selected}")
# Checks if trend has been selected then calls the install_trend() from trend.py
if trend_selected == 1:
logger.info("Attempting to install Trend")
install_trend()
# Checks if Kaseya has been selected then calls the install_kaseya from kaseya.py
if kaseya_selected == 1:
logger.info("Attempting to install Kaseya")
install_kaseya()
def create_checkboxes(packages_dict, checkboxes_dict, software_name):
for domain, name in packages_dict.items():
if domain_name == domain:
var = tk.IntVar()
unique_key = f"{software_name}_{domain}" # Create the unique identifier
# Debug log
logger.info(f"Creating checkbox for {unique_key} with software name {software_name}")
if "Kaseya" in name:
var.trace_add("write", lambda *args: on_kaseya_checkbox_click(var))
elif "Trend" in name:
var.trace_add("write", lambda *args: on_trend_checkbox_click(var))
checkboxes_dict[unique_key] = var
ttk.Checkbutton(root, text=name, variable=var).pack(anchor=tk.W, padx=20)
# Log inside the loop to capture every domain
logger.info(f"Attempting to create checkboxes for domain {domain_name} found: {domain_name == domain}")
def submit():
global browser_checkboxes, kaseya_checkboxes, trend_checkboxes
all_checkboxes = {**browser_checkboxes, **kaseya_checkboxes, **trend_checkboxes}
logger.info(f"All checkboxes: {all_checkboxes}")
selected_options = [option for option, var in all_checkboxes.items() if var.get() == 1]
logger.info(f"Browser checkboxes: {browser_checkboxes}")
logger.info(f"Kaseya checkboxes: {kaseya_checkboxes}")
logger.info(f"Trend checkboxes: {trend_checkboxes}")
# This line will log or print the selected options for debugging.
logger.info(f"Currently selected options: {selected_options}")
# checks if any Browser or Program has been selected to intall
if not selected_options:
logger.info("No options were selected.")
label.config(text="You have not selected any browsers or programs to install. Please select at least 1.")
return
# Check which Browsers to install and invoke the respective functions
if "Chrome" in selected_options:
logger.info("Attempting to install Chrome")
install_chrome()
if "Firefox" in selected_options:
logger.info("Attempting to install Firefox")
install_firefox()
# Setting Key
kaseya_key = f"Kaseya_{domain_name}"
kaseya_selected = kaseya_checkboxes.get(kaseya_key, {}).get() if kaseya_key in kaseya_checkboxes else None
trend_key = f"Trend_{domain_name}"
trend_selected = trend_checkboxes.get(trend_key, {}).get() if trend_key in trend_checkboxes else None
logger.info(f"Kaseya checkbox value for {kaseya_key}: {kaseya_selected}")
logger.info(f"Trend checkbox value for {trend_key}: {trend_selected}")
# Checks if trend has been selected then calls the install_trend() from trend.py
if trend_selected == 1:
logger.info("Attempting to install Trend")
install_trend()
# Checks if Kaseya has been selected then calls the install_kaseya from kaseya.py
if kaseya_selected == 1:
logger.info("Attempting to install Kaseya")
install_kaseya()
分离 IntVar() 值检查可防止 Kaseya 被 Trend 覆盖。