1

I'm trying to make a GUI for my app, but I have hit a roadblock when trying to make a settings Toplevel. This Toplevel comes with tabs and setting buttons that start at the same state their respective settings are stored as from last settings/defaults.

Here is the exception I am currently getting:

Exception in Tkinter callback
Traceback (most recent call last):
  File "C:\Program Files\Python39\lib\tkinter\__init__.py", line 1885, in __call__
    return self.func(*args)
  File "KMIU 4\kmiu_dv7.pyw", line 38, in settings
    sett.display(main)
  File "KMIU 4\bk\settings.py", line 54, in __init__
    self.windowsettings(tab2)
  File "KMIU 4\bk\settings.py", line 23, in windowsettings
    if settings['Fullscreen'].get(): fs_butt.select()
AttributeError: 'Checkbutton' object has no attribute 'select'

Here is the bit of code that is causing the issue:

def windowsettings(self, tab):
        global settings
        text = Label(tab, text ="sample text")
        text.grid(columnspan = 2)
        fs_butt = Checkbutton(
            tab, 
            text="Fullscreen",
            command=lambda: settings['Fullscreen'].set(not settings['Fullscreen'].get()))
        print(settings)
        fs_butt.grid(row=1)
        if settings['Fullscreen'].get(): fs_butt.select()
  • I bit more of code might help. Well I also think you need to pass on an `BooleanVar()` as the `variable` for the `fs_butt` and use `your_var_name.set(True)` to select it? – Delrius Euphoria Oct 31 '20 at 22:23
  • 1
    You appear to be using a ttk checkbutton rather than a tk checkbutton. Is that what you're doing? If so, the error is correct: a ttk checkbutton doesn't have a `select` method. Please provide a complete [mcve], including the imports. This is one of the dangers of using a wildcard import. – Bryan Oakley Oct 31 '20 at 22:37

1 Answers1

2

For me in my code with tk.Checkbutton, select() works, and ive seen some other people having the same issue, not sure whats causing it(maybe your using ttk.Checkbutton), but here is a way around:

  1. First assign a BooleanVar() to your checkbutton:
var = BooleanVar()
....
fs_butt = Checkbutton(tab,variable=var,......) #same for ttk.Checkbutton(..) too
  1. Now to set the value of the variable to True, to select, and False to deselect:
if settings['Fullscreen'].get():
    var.set(True)

Or maybe your using ttk.Checkbutton which does not have select() and deselect()

Delrius Euphoria
  • 14,910
  • 3
  • 15
  • 46