I am trying to use python and tkinter to make a program that run programs that have been selected in a check box.
import sys
from tkinter import *
import tkinter.messagebox
def runSelectedItems():
if checkCmd == 0:
labelText = Label(text="It worked").pack()
else:
labelText = Label(text="Please select an item from the checklist below").pack()
checkBox1 = Checkbutton(mGui, variable=checkCmd, onvalue=1, offvalue=0, text="Command Prompt").pack()
buttonCmd = Button(mGui, text="Run Checked Items", command=runSelectedItems).pack()
That is the code but I don't understand why it doesn't work?
Thanks.
You need to use an
IntVar
for the variable:In other news, the idiom:
Is not a very good one. In this case,
widget
will always beNone
since that is what is returned byWidget.pack()
. In general, you should create your widget and make it aware of the geometry manager in 2 separate steps. e.g.: