Following the TkDocs Tutorial (http://www.tkdocs.com/tutorial/widgets.html#checkbutton) I am trying to set up a check box, but I can't follow exactly what I should be doing to 'get' the toggled value.

    self.valAStatus = StringVar()
    self.checkA = ttk.Checkbutton(self.mainframe, text='A', command = lambda: self.getStatus(self.boxA, "A"),variable=self.valAStatus, onvalue='letter', offvalue='colour')

and

def getStatus(self, boxRef, value):
    boxRef.insert(1, value)

What I'm not sure on is how to get the either onvalue or offvalue from the self.checkA object

I'm not sure if I am looking at the StringVar self.valAStatus (that results in PY_VAR0 and has no attribute onvalue) or if I should be looking at the self.checkA object (that results in .40972728.40972656.40972800.41009024 and has no attribute onvalue).

I've probably missed something in the docs, but if anyone could point out what its doing, so I can get the (on|off)value I'd be obliged..

有帮助吗?

解决方案

The answer is self.valAStatus.get() which returns the value associated to that check box (in this case, self.valAStatus).

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top