Mike Driscoll Profile picture
Nov 20 โ€ข 4 tweets โ€ข 3 min read
#Python has many different GUI Toolkits. In this mini-thread, I'm going to show you how to write a "simple" plot with #wxPython

๐Ÿงต๐Ÿ๐Ÿ‘‡
Creating a plot with #wxPython doesn't take a TON of code, but most GUI frameworks do require a LOT more code than simple scripts.

Here is a pretty stripped down plotting example: Image
When you run the code in the previous tweet, your #Python graph will look like this:

#wxPython ๐Ÿ”ฅ Image
If you'd like to try this code out, you can get it in my tutorial @mousevspython

This tutorial also has a few other neat plotting examples you can use!

blog.pythonlibrary.org/2010/09/27/wxpโ€ฆ

โ€ข โ€ข โ€ข

Missing some Tweet in this thread? You can try to force a refresh
ใ€€

Keep Current with Mike Driscoll

Mike Driscoll Profile picture

Stay in touch and get notified when new unrolls are available from this author!

Read all threads

This Thread may be Removed Anytime!

PDF

Twitter may remove this content at anytime! Save it as PDF for later use!

Try unrolling a thread yourself!

how to unroll video
  1. Follow @ThreadReaderApp to mention us!

  2. From a Twitter thread mention us with a keyword "unroll"
@threadreaderapp unroll

Practice here first or read more on our help page!

More from @driscollis

Nov 21
One of the harder concepts to learn in #Python are decorators.

So let's take a few moments and learn about them!

๐Ÿงต๐Ÿ๐Ÿ‘‡
It's always good to start with a regular function. Why?

Because you create a decorator using functions!

This function, `doubler()` takes in a number and doubles it. That's it! Image
But wait! #Python functions are also objects. You can get their `__name__` and their docstring (`__doc__`), if they have one.

You can also get a listing of their other methods with `dir()`

What all this means is that you can pass a function to another function! Image
Read 11 tweets
Nov 21
Let's talk some more about sets in #Python in more detail!

The first thing to talk about is how to create a set. One way to do so is with curly braces.

Don't confuse this with dictionary creation though!

๐Ÿงต๐Ÿ๐Ÿ‘‡ Image
You can also create a set by using Python's `set()` class, which is built-in.

Here you use `set()` to cast a list to a set! ๐Ÿ๐Ÿ”ฅ

Note: Sets remove duplicate! Image
You can test if an item is in a #Python set by using Python's `in` operator: Image
Read 15 tweets
Nov 20
Let's talk about "unpacking" lists, tuples, and more with #Python!

The first unpacking example I want to show is how you can use a single asterisk to unpack all these different types!

๐Ÿ๐Ÿ”ฅ Image
You can also use the double-asterisk to unpack dictionaries.

In this example, you unpack a nested dictionary into another dictionary. Note that both dictionaries have the same key.

Since this is executed from left-to-right, you unpack and then overwrite the "x" key with 1 Image
Here's a more complicated example of dictionary unpacking.

You may need to re-read this a few times to fully understand what is going on here. Image
Read 4 tweets
Nov 15
Today is a great day to talk about one of #Python's most popular SQL ORMs - #SQLAlchemy!

SQLAlchemy is an Object Relational Mapper for Python. That means that it can translate Python code to SQL.

๐Ÿงต๐Ÿ‘‡๐Ÿ
Let's take a look at creating a database with #Python and #SQLAlchemy

You need to create classes that model tables in your database.

Then to create the actual database, you use `Base.metadata.create_all()` Image
Now let's add some data to our database using #Python and #SQLAlchemy

The following code shows how to add data to both our tables. It also shows how to add multiple rows of data all at once! ๐Ÿ๐Ÿ”ฅ Image
Read 6 tweets
Nov 13
It's the weekend, so now's a great time to talk about #Python and SQLite! ๐Ÿ

Python works with SQLite, a file-based database, right out of the box via its built-in `sqlite3` library.

Here's how you could connect to a SQLite database with Python: Image
When you use the `sqlite3` module in Python, you will be using regular SQL to work with it.

So to create a table, you would do something like this: Image
The following code shows how to insert one row of data into a table as well as how to insert multiple rows using SQL and sqlite3 in Python ๐Ÿ๐Ÿ”ฅ Image
Read 8 tweets
Nov 7
#Python includes several different ways to sort things. One handy way to sort is to use the built-in `sorted()` function!

Let's learn about that today!

#python_builtins_by_driscollis

๐Ÿงต๐Ÿ๐Ÿ‘‡
The `sorted()` function takes in an iterable and a couple of optional arguments.

In this example, you pass in a Python list and sort it from smallest to largest.

Then you set the optional `reverse` argument to True and sort from largest to smallest! ๐Ÿ๐Ÿ”ฅ
The `sorted()` function also takes an optional `key` parameter. This parameter is a function that is used to modify the sorting behavior.

In this example, you use `str.lower()` to sort the words of a sentence. It will compare all the words in lowercase while sorting.
Read 5 tweets

Did Thread Reader help you today?

Support us! We are indie developers!


This site is made by just two indie developers on a laptop doing marketing, support and development! Read more about the story.

Become a Premium Member ($3/month or $30/year) and get exclusive features!

Become Premium

Don't want to be a Premium member but still want to support us?

Make a small donation by buying us coffee ($5) or help with server cost ($10)

Donate via Paypal

Or Donate anonymously using crypto!

Ethereum

0xfe58350B80634f60Fa6Dc149a72b4DFbc17D341E copy

Bitcoin

3ATGMxNzCUFzxpMCHL5sWSt4DVtS8UqXpi copy

Thank you for your support!

Follow Us on Twitter!

:(