'IntVar' object has no attribute 'tk'. Did you mean: '_tk'?
时间: 2023-09-28 13:12:31 浏览: 50
This error message typically occurs when you try to access the 'tk' attribute of an instance of the 'IntVar' class in Tkinter, which does not exist.
Instead, you can access the 'get()' method of the 'IntVar' instance to retrieve the current value stored in the variable.
For example, if you have an instance 'my_var' of the 'IntVar' class, you can retrieve its value with:
```
value = my_var.get()
```
If you need to attach the variable to a widget, you can pass the 'my_var' instance as the 'variable' argument when creating the widget. For example, to create a checkbutton with the 'my_var' variable:
```
my_checkbox = tk.Checkbutton(root, text='My checkbox', variable=my_var)
```
This will create a checkbutton that is linked to the 'my_var' variable, so that its value changes depending on whether the checkbutton is checked or unchecked.