I want to add a ruler to a gui created with tkinter and matplotlib. There is already a custom toolbar but it currently only utilizes tools already provided:
class CustomToolbar(NavigationToolbar2TkAgg):
"""
A custom Matplotlib toolbar that allows for a lasso selection when no tool is selected
"""
def __init__(self, canvas_, parent_, edit_frame, app):
self.parent_frame = parent_
self.edit_frame = edit_frame
self.toolitems = (
('Home', "Reset zoom", 'home', 'home'),
('Back', 'Undo one zoom step', 'back', 'back'),
('Forward', 'Redo one zoom step', 'forward', 'forward'),
(None, None, None, None),
(None, None, None, None),
(None, None, None, None),
('Pan', 'Activate pan', 'move', 'pan'),
('Zoom', 'Activate zoom', 'zoom_to_rect', 'zoom'),
# ("Lasso", "Activate lasso", "hand", "lasso")
)
self.app = app
NavigationToolbar2TkAgg.__init__(self, canvas_, parent_)
def pan(self):
NavigationToolbar2TkAgg.pan(self)
if self._active:
self.edit_frame.config(background='white', text='Pan')
else:
self.edit_frame.config(background='red', text='Draw')
self.app.change_class()
def zoom(self):
NavigationToolbar2TkAgg.zoom(self)
if self._active:
self.edit_frame.config(background='white', text='Zoom')
else:
self.edit_frame.config(background='red', text='Draw')
self.app.change_class()
if either the pan or zoom are 'unselected' the drawing tool is used which acts as a lasso. The lasso is used to select the region you would like to label and then it shows up as labeled on the right hand image. Here is an image of what the GUI looks like with "twin boundary" as the currently selected label (which is dark pink when unselected).
So, There was a ruler tool created by someone on github: https://github.com/terranjp/matplotlib-tools
And I have found a couple closely related articles: create the icon: Add toolbar button icon matplotlib different method for custom toolbar: http://dalelane.co.uk/blog/?p=778
I am not sure how to implement the button/tool in a GUI environment. Any direction here would be greatly appreciated.