def _start_drag_col(self, event):
        """Start dragging a column"""
        # identify dragged column
        col = self.identify_column(event.x)
        self._dragged_col = ttk.Treeview.column(self, col, 'id')
        # get column width
        self._dragged_col_width = w = ttk.Treeview.column(self, col, 'width')
        # get x coordinate of the left side of the column
        x = event.x
        while self.identify_region(x, event.y) == 'heading':
            # decrease x until reaching the separator
            x -= 1
        x_sep = x
        w_sep = 0
        # determine separator width
        while self.identify_region(x_sep, event.y) == 'separator':
            w_sep += 1
            x_sep -= 1
        if event.x - x <= self._im_drag.width():
            # start dragging if mouse click was on dragging icon
            x = x - w_sep // 2 - 1
            self._dragged_col_x = x
            # get neighboring column widths
            displayed_cols = self._displayed_cols
            self._dragged_col_index = i1 = displayed_cols.index(self._dragged_col)
            if i1 > 0:
                left = ttk.Treeview.column(self, displayed_cols[i1 - 1], 'width')
            else:
                left = None
            if i1 < len(displayed_cols) - 1:
                right = ttk.Treeview.column(self, displayed_cols[i1 + 1], 'width')
            else:
                right = None
            self._dragged_col_neighbor_widths = (left, right)
            self._dx = x - event.x  # distance between cursor and column left border
            # configure dragged column preview
            self._visual_drag.column(self._dragged_col, width=w)
            self._visual_drag.configure(displaycolumns=[self._dragged_col])
            if 'headings' in tuple(str(p) for p in self['show']):
                self._visual_drag.configure(show='headings')
            else:
                self._visual_drag.configure(show='')
            self._visual_drag.place(in_=self, x=x, y=0, anchor='nw',
                                    width=w + 2, relheight=1)
            self._visual_drag.state(('active',))
            self._visual_drag.update_idletasks()
            self._visual_drag.yview_moveto(self.yview()[0])
        else:
            self._dragged_col = None
def _start_drag_col ( self , event ) : col = self . identify_column ( event . x ) self . _dragged_col = ttk . Treeview . column ( self , col , 'id' ) self . _dragged_col_width = w = ttk . Treeview . column ( self , col , 'width' ) x = event . x while self . identify_region ( x , event . y ) == 'heading' : x -= 1 x_sep = x w_sep = 0 while self . identify_region ( x_sep , event . y ) == 'separator' : w_sep += 1 x_sep -= 1 if event . x - x <= self . _im_drag . width ( ) : x = x - w_sep // 2 - 1 self . _dragged_col_x = x displayed_cols = self . _displayed_cols self . _dragged_col_index = i1 = displayed_cols . index ( self . _dragged_col ) if i1 > 0 : left = ttk . Treeview . column ( self , displayed_cols [ i1 - 1 ] , 'width' ) else : left = None if i1 < len ( displayed_cols ) - 1 : right = ttk . Treeview . column ( self , displayed_cols [ i1 + 1 ] , 'width' ) else : right = None self . _dragged_col_neighbor_widths = ( left , right ) self . _dx = x - event . x self . _visual_drag . column ( self . _dragged_col , width = w ) self . _visual_drag . configure ( displaycolumns = [ self . _dragged_col ] ) if 'headings' in tuple ( str ( p ) for p in self [ 'show' ] ) : self . _visual_drag . configure ( show = 'headings' ) else : self . _visual_drag . configure ( show = '' ) self . _visual_drag . place ( in_ = self , x = x , y = 0 , anchor = 'nw' , width = w + 2 , relheight = 1 ) self . _visual_drag . state ( ( 'active' , ) ) self . _visual_drag . update_idletasks ( ) self . _visual_drag . yview_moveto ( self . yview ( ) [ 0 ] ) else : self . _dragged_col = None
Start dragging a column