Skip main navigation

Example: using objects to create a GUI

Example: using objects to create a GUI
0.6
Here is another example of how updates are used in a program, this time to represent buttons on an interface. To create the buttons, we create two objects of the class pushbutton named button one, and button two.
16.8
Each button is an object in the program sense, and you can see that the buttons are each shown as a rectangle, giving us a visual representation of the button object.

Here is another example to show how objects are used in a program – this time to represent buttons on an interface. This is just a demonstration of the principle – there is no need to type this code yourself as it requires you to install some extra software to get it working.

To create the buttons, we create two objects of the class PushButton named button1 and button2:

button1 = PushButton(app, text="Button 1", command=do_stuff)
button2 = PushButton(app, text="Button 2", command=do_other_stuff)

Each button is now an object in the programming sense, and you can see that each button is shown as a rectangle, giving us a visual representation of the button object.

buttons

If you’re having trouble seeing the code in the video, make sure you are watching in HD and click the ‘Fullscreen’ button at the bottom right-hand side of the video.

Full screen

This article is from the free online

Object-oriented Programming in Python: Create Your Own Adventure Game

Created by
FutureLearn - Learning For Life

Our purpose is to transform access to education.

We offer a diverse selection of courses from leading universities and cultural institutions from around the world. These are delivered one step at a time, and are accessible on mobile, tablet and desktop, so you can fit learning around your life.

We believe learning should be an enjoyable, social experience, so our courses offer the opportunity to discuss what you’re learning with others as you go, helping you make fresh discoveries and form new ideas.
You can unlock new opportunities with unlimited access to hundreds of online short courses for a year by subscribing to our Unlimited package. Build your knowledge with top universities and organisations.

Learn more about how FutureLearn is transforming access to education