本文整理汇总了Python中tkinter.Checkbutton.deselect方法的典型用法代码示例。如果您正苦于以下问题:Python Checkbutton.deselect方法的具体用法?Python Checkbutton.deselect怎么用?Python Checkbutton.deselect使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tkinter.Checkbutton
的用法示例。
在下文中一共展示了Checkbutton.deselect方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: ProgressCheckButton
# 需要导入模块: from tkinter import Checkbutton [as 别名]
# 或者: from tkinter.Checkbutton import deselect [as 别名]
class ProgressCheckButton(Frame, Observable):
def __init__(self, parent, model, index, status_model):
Frame.__init__(self, parent)
Observable.__init__(self)
self.model = model
self.index = index
self.status_model = status_model
self.var = IntVar()
self.var.set(model.get_checked())
self.progress_var = IntVar()
self.progress_status = ProgressStatus.undefined
self.check_button = Checkbutton(self, text=model.get_label, variable=self.var, command=self._check_changed)
self.progress_bar = Progressbar(self, orient='horizontal', mode='indeterminate', variable=self.progress_var)
self.check_button.pack(side=LEFT, fill="both", expand=True)
self.model.add_listener(self._model_changed)
def _model_changed(self, new_status):
model_state = self.model.get_checked()
gui_state = self.var.get()
if model_state is not gui_state:
self.model.set_checked(gui_state)
def refresh_check(self):
if self.status_model.is_checked_force_reload():
self.check_button.select()
else:
self.check_button.deselect()
def is_checked(self):
return self.var.get()
def _progress_status_changed(self, new_status):
self._refresh_progress()
def _refresh_progress(self):
status = self.status_model.get_status()
if not status == self.progress_status:
if status == ProgressStatus.in_progress:
self.progress_bar.pack(side=RIGHT, fill="both", expand=True)
else:
self.progress_bar.pack_forget()
def _check_changed(self):
new_checked = self.var.get()
if new_checked is not self.model.get_checked():
self.model.set_checked(new_checked)
if new_checked is not self.status_model.is_checked():
self._notify(self.index, new_checked)
示例2: ProgressListBoxItem
# 需要导入模块: from tkinter import Checkbutton [as 别名]
# 或者: from tkinter.Checkbutton import deselect [as 别名]
class ProgressListBoxItem(Frame, Observable):
def __init__(self, parent, model):
Frame.__init__(self, parent)
Observable.__init__(self)
self._model = model
# Create variables and initialise to zero
self._checked_var = IntVar()
self._progress_var = IntVar()
self._checked_var.set(0)
self._progress_var.set(0)
self._current_gui_checked_state = CheckStatus.undefined
self._current_gui_progress_state = ProgressStatus.undefined
self.check_button = Checkbutton(self, text=model.get_label(), variable=self._checked_var, command=self._user_check_changed)
self.progress_bar = Progressbar(self, orient='horizontal', mode='indeterminate', variable=self._progress_var)
self.check_button.pack(side=LEFT, fill="both", expand=True)
self._update()
self._model.add_listener(self._model_changed)
def _model_changed(self):
self.update()
def _update(self):
# Update check status
model_check_state = self._model.get_check_status()
if model_check_state is not self._current_gui_checked_state:
self._current_gui_checked_state = model_check_state
# if self.status_model.is_checked_force_reload():
if model_check_state:
self.check_button.select()
else:
self.check_button.deselect()
# Update progress status
model_progress_state = self._model.get_progress_status
if not model_progress_state == self._current_gui_progress_state:
self._current_gui_progress_state = model_progress_state
if model_progress_state == ProgressStatus.in_progress:
self.progress_bar.pack(side=RIGHT, fill="both", expand=True)
else:
self.progress_bar.pack_forget()
def _user_check_changed(self):
new_checked = self._checked_var.get()
if new_checked is not self._model.get_check_status():
self._model.manual_set_checked(new_checked)