Dark theme

Graphical Interfaces: GUIs and the Web
[outline]


In this part we'll look at two important forms of user interaction: Graphical User Interfaces (GUIs) and the Web. For GUIs we'll see how to make a basic application with a menu. For the web, we'll see how to make a client-server system, build webpages, and process them for data.


First, let's look at how we build a basic application with its own window and menu system.

GUIs (powerpoint)

Further info:

You can find out more about TkInter on the TkInter library site. There are also a wide range of tutorials on the Python Wiki.

For wxPython, see the library website.

You can find a wide range of other alternatives listed on the Python Wiki GUI Programming page.


Quiz: A "callback" is _____________________

  1. a function passed to another piece of code such that later the function can be run by that code.
  2. a request to a function to return to the place the function is called after it runs.
  3. a request to busy code to work something out and return the answer when it can.

Correct! A callback is generally a function passed to another piece of code (for example a second function) under the expectation the function will be run by that code later. It is often used to communicate between applications or servers: I send you my function, and when you're ready, for example, you pass in data I want to get or process.


The other major interface for interacting with users is the Web. While Python isn't generally used for website building, it can be used for backend production and processing. Next we'll look at how the web works, before going on to look at how to process websites. Finally, we'll look at JavaScript, which is used directly in web pages, and is worth getting familar with. First up, how it all works.


How the Web works (powerpoint)

Further info:

You can find out more about sockets generally on Wikipedia and Python sockets specifically on the Python HowTo page.

List of commonly taken port numbers

Intro to TCP/IP. Many of the core protocols are laid out in Request for Comment (RFC) documents, which are, essentally, the progenitor of things like the Python PEPs. RFC 2549 is especially useful.

A variety of useful IP and DNS lookup tools can be found at DNS stuff. To find out your current IP Address, visit What'sMyIP.

You can find a brief introduction to HTML on our website, but for detailed and clear information across the board on Web tech, w3Schools is excellent.

HTML is a derivative of the Standard Generalized Markup Language specification. Both HTML and the SGML specification heavily influenced the development of XML, which is widely used for data formatting.

 


Quiz: The following markup prints ________________________________________

Old pond –
frog jumps in –
kerplunk.<BR />
Matsuo Bash&ocirc;

  1. four lines.
  2. two lines.
  3. no lines.

Correct! Remember that HTML renderers (i.e. web browsers) don't present the text as written, but as the markup dictates. As we only have one <BR /> line break, we only have two lines. Here they are:
Old pond – frog jumps in – kerplunk.
Matsuo Bashô
Notice that to get the "o" with a circumflex accent, and the "en-dashes" we've used "special characters". These are a bit like escape sequences. You can find a full list on Wikipedia.


Knowing how to write web pages helps us to then analyse them. We'll look at two ways of doig this. Firstly, using Python to explore and analyse the DOM from outside the page, and then using JavaScript to do the same job, in a very similar manner, when running inside the webpage itself. Hopefully this will also get you started on JavaScript, a useful language that makes a great addition to anyone's list of languages.


Web processing (powerpoint)

Further info:

For more information on the requests library, see its website, including details of how to process JSON.

For a list of server HTTP error codes, see Wikipedia. 418 errors are associated with Trojan Room queries.

For more on BeautifulSoup, see the library website.