checkbutton mit select() vor-wählen: 'NoneType' has no attr

Fragen zu Tkinter.
Antworten
egerlach
User
Beiträge: 43
Registriert: Samstag 14. März 2009, 21:32

Hallo,
warum kommt bei dem Versuch eines select() die Fehlermeldung:
Traceback (most recent call last):
File "aa.py", line 7, in <module>
Bc.select()
AttributeError: 'NoneType' object has no attribute 'select'

Code: Alles auswählen

import Tkinter as tk
root=tk.Tk()
b=tk.StringVar()
Bc=tk.Checkbutton(root, text="ddddddd", variable=b).grid()
Bc.select()
tk.mainloop()
Zur Info:
http://effbot.org/tkinterbook/radiobutt ... ect-method
deselect() Deselects the button.
flash() Redraws the button a couple of times, alternating between active and normal appearance. This can be useful when debugging, or to indicate when some other user action has activate the button.
invoke() Calls the command associated with the button.
select() Selects the button.
yipyip
User
Beiträge: 418
Registriert: Samstag 12. Juli 2008, 01:18

Bc ist None, weil das der Rückgabewert von grid() ist.
Was Du schreiben willst ist:

Code: Alles auswählen

...
Bc=tk.Checkbutton(root, text="ddddddd", variable=b)
Bc.grid()
Bc.select()
...
:wink:
yipyip
Antworten