You are on page 1of 1

GE 120 2019-20 2nd Semester

Machine Exercise 9: GUI – Graphing I

Objectives:
• To use PySimpleGUI to graph a curve.
• To use PySimpleGUI elements such as Menu, and Graph

Implement an application with GUI using PySimpleGUI that graphs a given curve.

Do the above as follows:

1. Refer to the PySimpleGUI Cookbook sections entitled Menus to see the sample code
for creating menus and handling the associated events; and Graphing with Graph
Element to see how to instantiate the element, and use it to do graphing (curve
plotting).
2. Define and instantiate two major child elements (widgets) of the main window, a main
Menu element, and a Graph element.
• The main menu (bar) consists of two menus: App and Help.
• App menu has the menu items Plot, and Exit; and, Help menu has only a single item
About.
• When Plot is selected, the curve exp(-x)sin(x) is plotted from x = 0 to 10 (in radians)
by plotting curve points as small filled green circles, with x- and y-axes also drawn.
Note that you need to derive from the given the bounds needed in instantiating the
Graph element. It is also up to you how big the canvas (part of the Graph element) as
long as the graph(the plot) is readable enough.
• The menu item Exit closes the entire application.
• The single menu item About when clicked simply shows a popup message describing
what the application does.
3. As x-values between the first and last x-values are needed, define a function that
generates x-values between x0 (the first), and xn (the last), where n is the number of
intervals. Call thus function gen_xs with 3 parameters: x0, xn, and n. The return value
is a list of the generated x-values including x0 and xn. For the problem, n should be
sufficiently large so the graph is accurate enough.
4. Similarly, define the function gen_ys that takes, as parameter, a list of x-values, and
calculates for each x-value the value of the above mentioned curve. The list of
generated y-values is the returned value.
5. Use the math module for functions exp(x), and sin(x) needed in graphing the curve at
the given and generated x-values, and also to have access to the value of pi.

Lastly, submit your Python file properly named to include the string GE120ME9 plus your
surname, and first and middle name initials.
---------- END ----------

You might also like