0

我对 checkbtn 值有一点问题。

这是我的代码:

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)

问题是当我选中该框时我的变量没有改变

非常感谢你!

4

1 回答 1

1

可能您使用Tk(). Toplevel()在这种情况下,您应该使用(Not with )创建另一个窗口Tk()

这意味着在您的情况下,您应该将select_window = Tk()行更改为select_window = Toplevel()

于 2020-10-22T15:16:36.690 回答