【发布时间】:2022-10-23 00:48:36
【问题描述】:
我正在为我的 python 脚本制作一个 tkinter 应用程序。我想确保当用户勾选“自动退出”复选框时,脚本将在完成后自动退出 - 关闭 gui 应用程序。
但是如果用户这样做不是勾选此框,则脚本将照常停止,但 gui 应用程序将保持打开状态。我正在为 gui 使用开源基础,因为我认为它看起来不错。这主要仅用于个人使用和实验目的。
我怎样才能做到这一点?谢谢。
代码:
import tkinter
import customtkinter
import webbrowser
import pyautogui
def main_script():
webbrowser.open('https://www.google.com')
pyautogui.moveTo(500, 500)
# this is where I want the script to stop, but the gui app remaining open if checkbox is ticked.
# If not, then everything will close.
self.check_box_1 = customtkinter.CTkCheckBox(master=self.frame_right,
text="Auto exit")
self.check_box_1.grid(row=2, column=2, pady=20, padx=40, sticky="w")
【问题讨论】:
-
只需调用
self.check_box_1.get()来检查复选框是否在main_script()中被选中,然后根据结果做任何你想做的事情。
标签: python python-3.x tkinter pyautogui customtkinter