This class accepts the following parameters *in addition* to the parameters accepted by `tqdm`. Parameters ---------- grab : bool, optional Grab the input across all windows of the process. tk_parent : `tkinter.Wm`, optional
(self, *args, **kwargs)
| 31 | # TODO: @classmethod: write()? |
| 32 | |
| 33 | def __init__(self, *args, **kwargs): |
| 34 | """ |
| 35 | This class accepts the following parameters *in addition* to |
| 36 | the parameters accepted by `tqdm`. |
| 37 | |
| 38 | Parameters |
| 39 | ---------- |
| 40 | grab : bool, optional |
| 41 | Grab the input across all windows of the process. |
| 42 | tk_parent : `tkinter.Wm`, optional |
| 43 | Parent Tk window. |
| 44 | cancel_callback : Callable, optional |
| 45 | Create a cancel button and set `cancel_callback` to be called |
| 46 | when the cancel or window close button is clicked. |
| 47 | """ |
| 48 | kwargs = kwargs.copy() |
| 49 | kwargs['gui'] = True |
| 50 | # convert disable = None to False |
| 51 | kwargs['disable'] = bool(kwargs.get('disable', False)) |
| 52 | self._warn_leave = 'leave' in kwargs |
| 53 | grab = kwargs.pop('grab', False) |
| 54 | tk_parent = kwargs.pop('tk_parent', None) |
| 55 | self._cancel_callback = kwargs.pop('cancel_callback', None) |
| 56 | super().__init__(*args, **kwargs) |
| 57 | |
| 58 | if self.disable: |
| 59 | return |
| 60 | |
| 61 | if tk_parent is None: # Discover parent widget |
| 62 | try: |
| 63 | tk_parent = tkinter._default_root |
| 64 | except AttributeError: |
| 65 | raise AttributeError( |
| 66 | "`tk_parent` required when using `tkinter.NoDefaultRoot()`") |
| 67 | if tk_parent is None: # use new default root window as display |
| 68 | self._tk_window = tkinter.Tk() |
| 69 | else: # some other windows already exist |
| 70 | self._tk_window = tkinter.Toplevel() |
| 71 | else: |
| 72 | self._tk_window = tkinter.Toplevel(tk_parent) |
| 73 | |
| 74 | warn("GUI is experimental/alpha", TqdmExperimentalWarning, stacklevel=2) |
| 75 | self._tk_dispatching = self._tk_dispatching_helper() |
| 76 | |
| 77 | self._tk_window.protocol("WM_DELETE_WINDOW", self.cancel) |
| 78 | self._tk_window.wm_title(self.desc) |
| 79 | self._tk_window.wm_attributes("-topmost", 1) |
| 80 | self._tk_window.after(0, lambda: self._tk_window.wm_attributes("-topmost", 0)) |
| 81 | self._tk_n_var = tkinter.DoubleVar(self._tk_window, value=0) |
| 82 | self._tk_text_var = tkinter.StringVar(self._tk_window) |
| 83 | pbar_frame = ttk.Frame(self._tk_window, padding=5) |
| 84 | pbar_frame.pack() |
| 85 | _tk_label = ttk.Label(pbar_frame, textvariable=self._tk_text_var, |
| 86 | wraplength=600, anchor="center", justify="center") |
| 87 | _tk_label.pack() |
| 88 | self._tk_pbar = ttk.Progressbar( |
| 89 | pbar_frame, variable=self._tk_n_var, length=450) |
| 90 | if self.total is not None: |
nothing calls this directly
no test coverage detected