0

I have been making a GUI with Tkinter in Python 2.7 and I want to trigger the checkbox from within the code such that the checkbox get ticked whenever that function is read. For e.g Suppose I am reading a list of strings and whenever I come across a word in the list called enable I need to trigger that definite checkbox from an array of other checkboxes, such that it gets ticked; so whenever I run the program that checkbox, from an array of other checkboxes, is ticked. For now what this checkbox is doing if we check it it sends out the value enabled or disabled to the function force_download_function(i, var.get()). But I also want to make sure if we are reading from a list and we come across the word 'enabled' it shows a tick on that checkbox number equivalent to the index of the word 'enabled'

def make_force_download_button(i):
    var = StringVar()
    force_download_button_array[i] = Checkbutton(top, variable=var, onvalue='enabled', offvalue='disabled', command=lambda: force_download_function(i, var.get()))
    force_download_button_array[i].deselect()

    force_download_button_array[i].pack()
    force_download_button_array[i].place(height=30, width=30, x=420, y=(65 + ((i - 1) * 60)))
1
  • You can use select() to check the checkbutton and deselect() to uncheck it. Commented Aug 4, 2020 at 5:48

1 Answer 1

1

The code below assumes that you are looping through a list of words with a corresponding index as you stated. I use python 3 so the syntax may differ some.

list_of_words = ["disabled", "enabled", "disabled"]

for num in range(len(list_of_words)):
    if list_of_words[num] == "enabled":
        force_download_button_array[num].select()
    elif list_of_words[num] == "disabled":
        force_download_button_array[num].deselect()
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.