Esempio n. 1
0
class CheckBox(Widget):
    def __init__(self, master, **kwargs):
        self._value = IntVar()
        super().__init__(tk=ttk.Checkbutton(master=master,
                                            variable=self._value),
                         **kwargs)

        self._setter = self.connect_to_prop("value", self.on_changed_value)
        self._trace = self._value.trace_add(
            "write", lambda *_: self._setter(self._value.get()))

    def on_changed_value(self, value):
        self._value.set(value)

    def on_disposed(self):
        self._value.trace_remove("write", self._trace)
        self._value = None
        self._setter = None
Esempio n. 2
0
class Scale(Widget):
    def __init__(self, master, **kwargs):
        self._valuev = IntVar()
        super().__init__(tk=TkTickScale(master=master,
                                        orient=kwargs.get("node").get_attr(
                                            "orient", "horizontal"),
                                        variable=self._valuev),
                         **kwargs)
        self._setter = self.connect_to_prop("value", self.on_changed_value)
        self._trace = self._valuev.trace_add(
            "write", lambda *_: self._setter(self._valuev.get()))

    def on_changed_value(self, value):
        self._valuev.set(int(value))

    def on_disposed(self):
        self._valuev.trace_remove("write", self._trace)
        self._valuev = None
        self._setter = None