Looping Menu

Non-filter Components: 8 points


We’ll start by implementing the menu for your program. Your program should begin by printing a welcome to the user. You should then prompt the user in the console to enter the name of a file to load. You should use a try-except block to make sure that the file exists. If a FileNotFoundError occurs, instead of letting the raw error message show up, your program should print a message to the user letting them know that the file with the provided name does not exist and ask them to try again. You can either loop and ask again until they provide a valid file, or close the program.

Remember to also think about what other files or modules you are using and add the appropriate import statements.

Once you have an image loaded, display it. If you don’t remember how to load an image using the picture module, you can look at the code in warmupgram_run.py for a reminder. Next, use a while loop to repeatedly do the following:

  • print a list of possible operations,
  • prompt the user to select one of these operations to apply to their image,
  • apply the selected operation (create a distinct function for each operation), and
  • display the resulting image.

For example, the user might choose to reflect the image, then increase the contrast (of the now reflected image), and then blur (the now reflected and contrasted image). At each step, the user should be able to see the resulting image. For now, since you haven’t actually implemented the functions for the operations yet, you should implement placeholder conditional statements for all of the above and then test the filters as you implement them throughout the lab. One way to implement a placeholder statement is to write something like print("The Vertical Flip Filter will happen here."). Adding a statement like this for each choice the user might make will allow you to test that your menu is functioning correctly before you go on to actually implement the filters.

picture.save_picture() vs picture.display()

The picture module provides several methods for viewing graphics output. Until now, you’ve only been using picture.save_picture(). This function saves the picture as a standalone file in the repository. If you want to draw the picture to the screen, the picture module offers two functions:

  1. picture.display() creates or updates the image window with the latest drawing, then continues on in the program. We use display when we want to keep updating an image as the user interacts with the program.

  2. picture.run() also creates the image window with the latest drawing, but it pauses the program until the image window is closed. You might have noticed this function being used in the warmup. We use run whenever each image is independent of the others, and we want a user to be done with one image before moving on in the program.

Since the imagegram.py program is designed for users to keep applying different filters to the same image displayed on the screen, picture.display() is the most appropriate function to use. We call picture.display() after each applying each filter so that the user can see the latest effect.

You can find more information about picture.save_picture() and picture.display() in the picture module documentation.

ReadMe

We expect you to display the unedited image in the picture display window after the user inputs a file name!

The menu should keep prompting the user to select a filter until they select the Quit option. At the end of this part of the lab, a user interacting with your program should look something like this:

Welcome to Imagegram!  

Please enter a filename: crayons.jpg

Which of the following filters would you like to apply?

1. Make Negative
2. Make Grayscale
3. Flip Vertically
4. Scroll Horizontally
5. Zoom
6. Blur
0. Quit

Choice: 1

Which of the following filters would you like to apply?
1. Make Negative
2. Make Grayscale
3. Flip Vertically
4. Scroll Horizontally
5. Zoom
6. Blur
0. Quit

Choice: 0

Goodbye!

Reminder

As you make progress on your menu, don’t forget to commit and push your changes regularly.