【问题标题】:Tkinter checkbutton.select() not working on Checkbutton (Python 3)Tkinter checkbutton.select()不适用于Checkbutton(Python 3)
【发布时间】:2014-03-05 09:51:52
【问题描述】:

我正在编写一个程序,它从文件中读取数据,并相应地调整设置。这就是我创建检查按钮的方式:

should_auto = BooleanVar()    
autodetect = Checkbutton(root, text="Autodetect", var=should_auto, onvalue = True, offvalue = False, command=toggle_delay)
autodetect.grid(row=0, column=2, padx=7, pady=5, sticky=W)

然后我尝试使用以下方法“检查”它:

autodetect.select()

但这会返回以下错误:

Traceback (most recent call last):
  File "C:\Users\CedBook\Documents\GitHub\live-image-desktop-background\src\GUI.py", line 110, in <module>
    autodetect.select()
AttributeError: 'Checkbutton' object has no attribute 'select'

我也已经尝试过使用autodetect.set(True),但是我得到了几乎相同的错误,但是Checkbutton object has no attribute 'set' 我在 effbot.org 上看到了 .select(),但也许这不适用于 python 3?

【问题讨论】:

  • 使用autodetect.set(1)?
  • 仍然出现同样的错误。

标签: python checkbox widget tkinter tk


【解决方案1】:

你可以设置布尔值吗?

should_auto.set(True)

应该更新依赖它的复选框。

【讨论】:

  • 是的,会做到的......你打败了我;)
  • autodtect.set(1) 可能有效,但那是按钮,而不是变量。无论如何,谢谢你们。
  • AttributeError: 'Checkbutton' 对象没有属性 'set'
  • @Ath.Bar。听起来您正在尝试设置检查按钮的值而不是支持它的变量,请参阅should_auto 是BooleanVar 并作为var 关键字传递给Checkbutton 的OP。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2017-01-18
  • 2018-05-17
  • 2023-04-07
  • 2016-06-16
  • 2018-10-20
  • 1970-01-01
  • 2021-06-29
相关资源
最近更新 更多