문제

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