def _set_configure(self, cnf): "Internal function." kw_copy = check_param(self, 'sframe', {k: cnf.pop(k) for k in SFRAME_FEATURES if k in cnf}) self.cnf['scrollbar']['width'] = kw_copy.pop( 'scrollbarwidth', self.cnf['scrollbar']['width']) for key in kw_copy.copy(): if key == 'avoidmousewheel': l = list(self.cnf[key]) if isinstance(kw_copy[key], (tuple, list)): l.extend(kw_copy.pop(key)) else: l.append(kw_copy.pop(key)) self.cnf[key] = tuple(set(l)) else: self.cnf[key] = kw_copy.pop(key, self.cnf.get(key)) self.cnf['canvas']['width'] = cnf.pop( 'width', self.cnf['canvas']['width']) self.cnf['canvas']['height'] = cnf.pop( 'height', self.cnf['canvas']['height']) self._mouse_scrolling(self.cnf['mousewheel']) self._avoid_mousewheel(self.cnf['avoidmousewheel']) return cnf
def __init__(self, master=None, cnf={}, **kw): kw = _cnfmerge((cnf, kw)) self._stop_state = False self.after_id = ' ' cnf = dict( text=kw.pop('text', ''), font=kw.pop('font', 'TkDefaultFont'), fg=kw.pop('fg', 'black') if kw.get('fg') else kw.pop( 'foreground', 'black'), fps=kw.pop('fps', 30), justify=kw.pop('justify', 'left'), left_margin=kw.pop('left_margin', 10), initial_delay=kw.pop('initial_delay', 1000), end_delay=kw.pop('end_delay', 1000), smoothness=kw.pop('smoothness', 1), # 1 <= smooth < 1 disabledforeground=kw.pop('disabledforeground', 'grey')) cnf['foreground'] = cnf['fg'] cnf = {k: v for k, v in cnf.items() if v is not None} kw['height'] = kw.get('height', 24) kw['highlightthickness'] = kw.get('highlightthickness', 0) tkinter.Canvas.__init__(self, master=master, **kw) self.cnf = check_param(self, 'marquee', **cnf) self._set_text() _bind(self, className='configure', sequence='<Configure>', func=self._check)
def _check_param(self, cnf={}, **kw): kw = _cnfmerge((cnf, kw)) if 'gradient' in kw: if kw['gradient'] != 'default': cond = isinstance(kw['gradient'], (list, tuple)) if not cond or (cond and len(kw['gradient']) <= 1): raise tkinter.TclError( 'expected sequence of two color values but got "%s"' % kw['gradient']) for c in kw['gradient']: self.winfo_rgb(c) kw = check_param(self, 'colorscale', kw) return kw
def __init__(self, master=None, cnf={}, **kw): kw = _cnfmerge((cnf, kw)) kw['class_'] = kw.get('class_', 'Sframe') self._after_ids = {} self._over_scrollbar = False cnf = {} cnf['scrollbarwidth'] = kw.pop('scrollbarwidth', 10) cnf['mousewheel'] = kw.pop('mousewheel', True) cnf['avoidmousewheel'] = kw.pop('avoidmousewheel', ()) cnf['autohidescrollbar'] = kw.pop('autohidescrollbar', False) cnf['autohidescrollbardelay'] = kw.pop('autohidescrollbardelay', 1000) cnf['canvas'] = kw.pop( 'canvas', tkinter.Canvas(master=master, highlightthickness=0, width=kw.pop('width', 250), height=kw.pop('height', 250))) cnf['scrollbar'] = kw.pop( 'scrollbar', tkinter.Scrollbar(cnf['canvas'], orient='vertical', width=cnf.get('scrollbarwidth'))) tkinter.Frame.__init__(self, cnf['canvas'], **kw) self.cnf = check_param(self, 'sframe', **cnf) self.cnf['canvas']['bg'] = self['bg'] if not self.cnf['autohidescrollbar']: self.cnf['scrollbar'].place( relx=1, rely=0, anchor='ne', relheight=1) self.cnf['scrollbar'].configure(command=self.cnf['canvas'].yview) self.cnf['canvas'].configure(yscrollcommand=self.cnf['scrollbar'].set) self.cnf['canvas'].create_window( 0, 0, anchor='nw', tags="window", window=self, width=self.cnf['canvas'].winfo_reqwidth()-self.cnf['scrollbar'].winfo_reqwidth()) self.cnf['canvas'].bind("<Configure>", self._configure_height, add="+") _bind(self, className='configure', sequence='<Configure>', func=self._configure_window) _bind(self, className='auto_hide_motion', sequence='<Motion>', func=self._auto_hide_scrollbar) _bind( self['scrollbar'], className='auto_hide_motion', sequence='<Enter>', func=lambda _: self._auto_hide_scrollbar('show')) _bind( self['scrollbar'], className='auto_hide_motion', sequence='<Leave>', func=self._auto_hide_scrollbar) self._mouse_scrolling(self.cnf['mousewheel']) self._avoid_mousewheel(self.cnf.get('avoidmousewheel')) self._geometryManager()
def _configure(self, cmd, cnf, kw): """Internal function.""" kw = _cnfmerge((cnf, kw)) diff = set(self.keys()).difference( list(tkinter.Canvas._configure(self, cmd, None, None))) for i in diff: if i in kw: self.cnf.update(check_param(self, 'marquee', {i: kw.pop(i)})) self._set_text() self._set_height() values = tkinter.Canvas._configure(self, cmd, None, kw) if values is not None and isinstance(values, dict): values.update(self.cnf.copy()) for i in list(values.copy()): if i not in MARQUEE_PROPERTIES: values.pop(i) return values