Setting up a broad GUI structure

Let's now set up the broad GUI elements of our program. We will create a PaintApplication class in 6.01.py. Since we want to draw the menu using our framework, we import the framework into our file and inherit from the Framework class as follows:

import framework

class PaintApplication(framework.Framework):

def __init__(self, root):
super().__init__(root)
self.create_gui()

The __init__ method calls another method, create_gui, which is responsible for creating the basic GUI structure for our program.

The create_gui method simply delegates the task to five separate methods, each being responsible for creating one section of the GUI as follows (see code 6.01.py):

def create_gui(self):
self.create_menu()
self.create_top_bar()
self.create_tool_bar()
self.create_drawing_canvas()
self.bind_menu_accelrator_keys()

These five methods together build a structure as shown in the following screenshot (see code 6.01.py):

We have written similar code in all previous chapters, hence we will not reproduce the code for these five methods here. Note, however, a few things about the code in 6.01.py:

  • Since we want to use the framework, we inherit from the Framework class and call its __init__ method using super()
  • The create_menu method specifies the tuple for our menu definition and calls the build_menu method defined earlier in our framework

We define a lot of empty methods that will be implemented later. Each empty method is added as a command callback to individual menu items. The empty methods defined here are:

on_new_file_menu_clicked()
on_save_menu_clicked()
on_save_as_menu_clicked()
on_close_menu_clicked()
on_canvas_zoom_out_menu_clicked()
on_canvas_zoom_in_menu_clicked()
on_undo_menu_clicked()
on_about_menu_clicked()

This gives us a broad GUI structure for our program. Next, we will look at interacting with the drawing canvas.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.16.75.165