Python for Beginners
eBook - ePub

Python for Beginners

Learn the Fundamentals of Computer Programming

J Foster

Share book
  1. English
  2. ePUB (mobile friendly)
  3. Available on iOS & Android
eBook - ePub

Python for Beginners

Learn the Fundamentals of Computer Programming

J Foster

Book details
Book preview
Table of contents
Citations

About This Book

With so much information about programming and online coding tutorials out there, it can be difficult to know where to start. Python for Beginners fills in the gap and provides a great place to start learning computer programming with Python. Using our bestselling, straightforward, step-by-step, visual approach, you'll learn to:

Download and install the python interpreter

Setup your development environment

Get started with python code and syntax

Use variables

Use data types such as integers, strings, lists, tuples, sets, and dictionaries

Use different operators for arithmetic, assignment and Boolean operations

Use selection statements such as if and elif

Use iteration statements such as for and while loops

How to read from and write to files

Create your own functions

Handle program exceptions

Create simple graphic user interfaces using Python tkinter module

Create simple games using the PyGame module.

Techniques are illustrated step-by-step using screen prints, example code, and video demos, together with concise, easy to follow text from an established expert in the field. If you want to learn to code quickly and easily with Python, this is the guide you need.

Frequently asked questions

How do I cancel my subscription?
Simply head over to the account section in settings and click on “Cancel Subscription” - it’s as simple as that. After you cancel, your membership will stay active for the remainder of the time you’ve paid for. Learn more here.
Can/how do I download books?
At the moment all of our mobile-responsive ePub books are available to download via the app. Most of our PDFs are also available to download and we're working on making the final remaining ones downloadable now. Learn more here.
What is the difference between the pricing plans?
Both plans give you full access to the library and all of Perlego’s features. The only differences are the price and subscription period: With the annual plan you’ll save around 30% compared to 12 months on the monthly plan.
What is Perlego?
We are an online textbook subscription service, where you can get access to an entire online library for less than the price of a single book per month. With over 1 million books across 1000+ topics, we’ve got you covered! Learn more here.
Do you support text-to-speech?
Look out for the read-aloud symbol on your next book to see if you can listen to it. The read-aloud tool reads text aloud for you, highlighting the text as it is being read. You can pause it, speed it up and slow it down. Learn more here.
Is Python for Beginners an online PDF/ePUB?
Yes, you can access Python for Beginners by J Foster in PDF and/or ePUB format, as well as other popular books in Informatique & Programmation en Python. We have over one million books available in our catalogue for you to explore.

Information

Year
2020
ISBN
9781913151171

Building an Interface

Modern computer applications are built with graphic user interfaces in mind. The user interacts with the application using windows, icons, menus and a mouse pointer rather than console-based I/O.
To create a graphic user interface using Python you’ll need use Tkinter (Tk interface). This module is bundled with standard distributions of Python for all platforms.
For this section, take a look at the video demos
www.elluminetpress.com/pygraphics
You’ll also need the source files in the directory Chapter09.

Creating a Window

The first thing you need to do is import the tkinter module into your program. To do this, use
from tkinter import *
To create a window use the Tk() method
window = Tk()
Add a title
window.title(‘Window Title’)
Set the initial size and position of the window. Use the .geometry() method.
window.geometry(“800x600+50+20”)
The first two numbers in this case ‘800x600’, sets the window size. Set this to the desired window size in pixels. This could be 1280x720, 1920x1080, and so on.
The second two numbers in this case ‘50+20’, sets the initial position of the window on the screen using x and y co-ordinates
Lets take a look at a program. Open window.py. Here, we’ve created a window. You can do this using the Tk() function and assign it to a window object.
We’ve sized the window so that is 640 pixels wide by 480 pixels high. We’ve also positioned the window 500 pixels across from the top left by 20 pixels down. You can do this using the .geometry() method. This is the initial size and position of the window on screen.
We’ve also added a window title. You can do this using the .title() method. This helps to identify your app.
Finally to make the window appear, we need to enter the Tkinter event loop. You can do this with the .mainloop() method.
window.mainloop()
This is an infinite loop used to run the application and is called an event loop. The .mainloop() method waits for an event such as a key press, or mouse click events from the window system and dispatches them to the application widgets (frames, buttons, menus, etc).
2323__p...

Table of contents