Adding functionality to menu items
Recall that, at the time of creating our menu using the Framework class, we created empty methods that were linked to our menu items. We now modify those empty methods to make them functional (see code 6.09.py
)
File | New Menu: The canvas delete method can be used to delete an item, given an item-specifier. Here we use ALL
to delete all items from the canvas:
def on_new_file_menu_clicked(self, event=None):
self.start_new_project()
def start_new_project(self):
self.canvas.delete(ALL)
self.canvas.config(bg="#ffffff")
self.root.title('untitled')
File | Save, File | Save As: Tkinter lets you save canvas objects as a postscript file using the command postscript()
. Note, however, that the resulting postscript file cannot save images or any widgets embedded on the canvas. Further, note that the pickling of Tkinter widgets or saving to .jpg
or .png
formats is not possible. This is one of the major limitations of Tkinter...