簡體   English   中英

如何使用按鈕單擊來確定是否已單擊/選中檢查按鈕以運行可執行文件? (與 tkinter)

[英]How do I use a button click to determine if a check button has been clicked/checked in order to run an executable? (with tkinter)

GUI 本身的工作原理是它會顯示文本和兩個復選框,但是當我選中一個框並點擊“單擊開始”按鈕時,什么也沒有發生。

這是我的代碼:

import tkinter
import os

window = tkinter.Tk()

window.title("Startup Menu")

tkinter.Label(window, text="Choose the applications to start:", justify=tkinter.LEFT, padx=20).pack()


# N
n_clicked = tkinter.IntVar()
n_check = tkinter.Checkbutton(window, text="N", variable=n_clicked)
n_check.pack()
# S
s_clicked = tkinter.IntVar()
s_check = tkinter.Checkbutton(window, text="S", variable=s_clicked)
s_check.pack()



# Startup button that executes the selected applications
def click():
    if n_clicked == 1:
        os.startfile(r"(file location)")
    if s_clicked == 1:
        os.startfile(r"(file location)")


# Start selected applications button
start_up = tkinter.Button(window, text="Click to start", command=click).pack()

window.mainloop()

tkinter 變量使用get()set()方法來處理它們。

if n_clicked.get():

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM