Contact FutureLearn for Support
Skip main navigation
We use cookies to give you a better experience, if that’s ok you can close this message and carry on browsing. For more info read our cookies policy.
We use cookies to give you a better experience. Carry on browsing if you're happy with this, or read our cookies policy for more information.

Skip to 0 minutes and 1 secondHere 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.

Skip to 0 minutes and 17 secondsEach 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.

Example: using objects to create a GUI

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

Share this video:

This video is from the free online course:

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

Raspberry Pi Foundation