0

I have a little problem with the checkbtn value.

Here is my code:

def select_data():
        select_window = Tk()

        var_autotrader = IntVar()
        check_sites_autotrader = Checkbutton(select_window, text = 'autotrader', variable = var_autotrader)
        var_bestcarfinder = IntVar()
        var_cardady = IntVar()
        var_cars = IntVar()
        var_car_gurus = IntVar()
        var_iseecars = IntVar()
        var_truecar = IntVar()

        check_sites_bestcarfinder = Checkbutton(select_window, text = 'bestcarfinder', variable = var_bestcarfinder)
        check_sites_cardaddy = Checkbutton(select_window, text = 'cardady', variable = var_cardady)
        check_sites_cars = Checkbutton(select_window, text = 'cars.com', variable = var_cars)
        check_sites_car_gurus = Checkbutton(select_window, text = 'car gurus', variable = var_car_gurus)
        check_sites_iseecars = Checkbutton(select_window, text = 'iseecars', variable = var_iseecars)
        check_sites_truecar = Checkbutton(select_window, text = 'truecar', variable = var_truecar)

        check_sites_autotrader.grid(row = 0, column = 0, sticky = W)
        check_sites_bestcarfinder.grid(row = 1, column = 0, sticky = W)
        check_sites_cardaddy.grid(row = 2, column = 0, sticky = W)
        check_sites_cars.grid(row = 3, column = 0, sticky = W)
        check_sites_car_gurus.grid(row = 4, column = 0, sticky = W)
        check_sites_iseecars.grid(row = 5, column = 0, sticky = W)
        check_sites_truecar.grid(row = 6, column = 0, sticky = W)
         def upload_selected_data():
            print(var_autotrader.get())// This one does not give me 1 when check is on
            

        btn = Button(select_window, text = 'go!',  command = upload_selected_data)
        btn.grid(row = 7, column = 0, sticky = W+E)

The trouble is that my variable is not changing when I check the box

Thank you very much!

7
  • Does this answer your question? Tkinter Checkbuttons not changing the variable value Commented Oct 21, 2020 at 13:29
  • No, becasue that window this is a main window. Thank you! Commented Oct 21, 2020 at 13:45
  • The code you posted works as expected for me on python 3.6.8 Win10. I think more code or information is needed to see where your problem is since it doesn't seem to be in this isolated piece of code. Commented Oct 21, 2020 at 13:57
  • Does this code really reproduce the problem? I don't see where you're calling mainloop, so it would be impossible for the user to even see the window much less interact with it. There also appears to be an indentation error with def upload_selected_data Commented Oct 21, 2020 at 14:18
  • If select_window is passed to all IntVar() like IntVar(select_window), do you get what you want? If yes, then it is definitely select_window is not the root window. Commented Oct 21, 2020 at 14:37

1 Answer 1

1

Probably you created your "main window" with Tk(). In this case you should create another window with the Toplevel() (Not with Tk()).

It means in your case you should change the select_window = Tk() line to select_window = Toplevel()

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.