Exercises

Here are some exercises for you to try on your own. Solutions are available at http://pragprog.com/titles/gwpy3/practical-programming.

  1. Write a GUI application with a button labeled “Goodbye.” When the button is clicked, the window closes.
  2. Write a GUI application with a single button. Initially the button is labeled 0, but each time it is clicked, the value on the button increases by 1.
  3. What is a more readable way to write the following?
     x = ​lambda​: y
  4. A DNA sequence is a string made up of As, Ts, Cs, and Gs. Write a GUI application in which a DNA sequence is entered, and when the Count button is clicked, the number of As, Ts, Cs, and Gs are counted and displayed in the window (see the following image).
    images/gui/count.png
  5. In Defining Our Own Functions, we wrote a function to convert degrees Fahrenheit to degrees Celsius. Write a GUI application that looks like the following image.
    images/gui/tempConvert.png

    When a value is entered in the text field and the Convert button is clicked, the value should be converted from Fahrenheit to Celsius and displayed in the window, as shown in the following image.

    images/gui/tempConvert2.png
  6. Rewrite the text editor code from Using Menu, as an object-oriented GUI.
..................Content has been hidden....................

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