Skip to content Skip to sidebar Skip to footer

Python Form: Using Tkinter --> Run Script Based On Checked Checkboxes In Gui

I have created the following checkbox popup in Python 3.5 using tkinter (see image) with the following code: from tkinter import * class Checkbar(Frame): def __init

Solution 1:

The problem is that your Checkbar class has no __getitem__ method so lng[1] will trigger an error. To do lng[1] == 1 without errors, just add the following method to you rCheckbar class:

def__getitem__(self, key):
    return self.vars[key].get()

That way lng[i] will return the value of the i-th IntVar of the Checkbar

Solution 2:

You need to explicitly cast to the same types to compare. Try this:

ifint(lng[1]) == 1:
    print ('test')

or

if lng[1] == str(1):
    print ('test')

Post a Comment for "Python Form: Using Tkinter --> Run Script Based On Checked Checkboxes In Gui"