Starting from:

$24.99

10.009 Week 11 Solution

• Homework problems : Same as for the cohort session problems.
• Exercises: These are practice problems and will not be graded. You are encouraged to solve these to enhance your programming skills. Being able to solve these problems will likely help you prepare for the end of term examination.
Objectives
1. Develop GUI application in Kivy.
2. Create window and common widgets.
3. Invoke callback function to bind event
Problems: Cohort sessions
1. GUI: alternate message: Write a program that alternates between two messages displayed on a canvas, ”Programming is fun” and ”It is fun to program,” as shown in the Figure 1. The program should alternate based on a touch down event, such as a left mouse click. Use the bind method with the event on_touch_down. Create a callback to a method called def alternate(self, instance, touch).

Figure 1: Alternate message on a mouse click.
2. GUI: slide detection Write a program that displays a label ”Slide Me” at the beginning. The program should handle the on_touch_move event on the label by calling the method def detect(self, instance, touch). The method should change the text of the label based on the direction of the slide movement. For example, when the user slides the screen to the left, it should display ”Slide Left”. When the user slide the screen to the right, it displays ”Slide Right” (Figure 2). Do the same with up and down. You can use touch.dx and touch.dy to detect the slide movement.
3. GUI: investment-value calculator: Write a program that calculates the future value of an investment, at a given interest rate for a specified number of years. The formula for the calculation is as follows:
futureV alue = investmentAmount × (1 + monthlyInterestRate)years×12 (1)
Use text fields for users to enter the investment amount, years, and interest rate. Display the future amount in a text field when the user clicks the Calculate button as shown in Figure 3.
4. GUI: switch screen: Write a program to switch between screens. When the program runs, it should display two buttons: one should bring the user to the Settings screen, while the

Figure 2: Slide Detection Application.

Figure 3: Investment calculator.
other one should allow the user to quit the application. If the user presses the Settings button, the screen will bring the user to another screen. In this second screen, it will display a label with the text ”Settings”, and a button ”back to Menu”. If the user press the button ”back to Menu”, it should bring the user back to the previous screen. See the snapshots to have a better idea of the question requirements.

Figure 4: Switch Screen.
End of Problem Set 11.

More products