O'Reilly logo

Tkinter GUI Programming by Example by David Love

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Python's module system

Python's module system is something we have been using throughout the book. It is what lies behind the import statements.

All that we need to do in order to create a module is make a Python file. It really is that simple. Let's take a small example. Create a new folder to hold our example and add a short simple file:

# mymod.pymyvariable = 15def do_a_thing():    print('mymod is doing something')def do_another_thing():    print('mymod is doing something else, and myvariable is', myvariable)

This may look the same as any normal Python file, but we can treat this as a reusable module if we want to. To demonstrate, open up a terminal window, change into the directory you have just created with this file in, and then run the Python ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required