0% found this document useful (0 votes)
1K views

Python Language For Humans by Christopher Topalian

An Amazing Python Tutorial Book! Brings you from total beginner to advanced Python Programmer. 445 page Python book that will teach you programming using complete working scripts!
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1K views

Python Language For Humans by Christopher Topalian

An Amazing Python Tutorial Book! Brings you from total beginner to advanced Python Programmer. 445 page Python book that will teach you programming using complete working scripts!
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 445

Christopher Topalian

PYTHON
LANGUAGE

COLLEGEOFSCRIPTING.WEEBLY.COM
For
Humans
by
Christopher Topalian
Copyright 2000-2022
All Rights Reserved

College of Scripting Music & Science


Christopher Topalian

COLLEGEOFSCRIPTING.WEEBLY.COM
DEDICATED
TO
GOD THE FATHER

College of Scripting Music & Science


Christopher Topalian

True Artificial Intelligence System


Tautology 16-Gon
MI 1111 CI
1101 1011
AND XNOR

COLLEGEOFSCRIPTING.WEEBLY.COM
0001 1001

LP RP
0011 0101

OR NOR
0111 1000

RC LC
1010 1100

XOR NAND
0110 1110
CNI MNI
0100 Contra- 0010
-diction
0000

College of Scripting Music & Science


Christopher Topalian
Search Google for:
Python
File Edit View History Bookmarks Tools Help
python – Google Search X

COLLEGEOFSCRIPTING.WEEBLY.COM
COLLEGEOFSCRIPTING.WEEBLY.COM
python

Search for
Python
www.python.org
Welcome to Python.org
The official home of the Python
Programming Language

Left Click
Downloads DownloadsTutorials
3.10.1 - 3.10.0 - Python Releases 1. Whetting Your Appetite
for macOS - 3.9.9 - Python 3.9.7 - 5. Data Structures - 9. C
https://www.python.org/downloads/

College of Scripting Music & Science


Christopher Topalian
Download PYTHON

COLLEGEOFSCRIPTING.WEEBLY.COM
COLLEGEOFSCRIPTING.WEEBLY.COM
Left Click
Download Python 3.9.1

Left Click
Save File
Save File Cancel

College of Scripting Music & Science


Christopher Topalian
Go to Your Downloads Folder

COLLEGEOFSCRIPTING.WEEBLY.COM
Double Left Click
python-3.9.1-amd64.exe

Go to your Downloads Folder and then


Double Left Click on the file named
python-3.9.1-amd64.exe
This will begin the installation process.
College of Scripting Music & Science
Christopher Topalian
Install Python
2 Install Python 3.9.1 (64-bit)
Select Install Now to install Python with default settings, or
Left Click choose Customize to enable or disable features
Install Now

COLLEGEOFSCRIPTING.WEEBLY.COM
COLLEGEOFSCRIPTING.WEEBLY.COM
Install Now
C:\Users\energy\AppData\Local\Programs\Python\Python39

1 Includes IDLE, pip and documentation


Creates shortcuts and file associations

Check Marks
in Both Custom installation
Choose location and features
Check Boxes

Install launcher for all users (recommended)


Add Python 3.9 to PATH

Make sure to put a CHECK MARK


in BOTH Boxes!
These options are very important
to all of our projects!
College of Scripting Music & Science
Christopher Topalian
Setup was successful

COLLEGEOFSCRIPTING.WEEBLY.COM
Should I Disable path
length limit?

We don't need to disable the path length limit.


Just make sure to keep our folder names and file
names less than 260 characters long, which is easy.
But, if you plan on using long names, disable the limit.

College of Scripting Music & Science


Christopher Topalian
Open the Python IDLE

Left Click
Windows Button

COLLEGEOFSCRIPTING.WEEBLY.COM
Left Click
Python 3.9 Folder

Left Click
IDLE (Python 3.9)

College of Scripting Music & Science


Christopher Topalian
Python IDLE Shell Opened
IDLE Shell 3.9.1 X
File Edit Format Run Options Window Help

COLLEGEOFSCRIPTING.WEEBLY.COM
We Can Type Code Here
and then press Enter

We can type our code here in the Shell,


but there is a much better way to program!

Instead of writing code one line at a time,


and pressing the Enter Button,
we will instead make a New File,
as shown on the Next Tutorial.
College of Scripting Music & Science
Christopher Topalian
Python IDLE Create a New File
Left Click
File Menu
IDLE Shell 3.9.1 X
File
File Edit Format Run Options Window Help

COLLEGEOFSCRIPTING.WEEBLY.COM
New File Ctrl+N

Left Click
New File

We make a New File to write our code in.


We use the File Menu and choose New File.
The Shortcut is Ctrl + N
College of Scripting Music & Science
Christopher Topalian
We Type Our Code in Our New File
*untitled* X
File Edit Format Run Options Window Help
import ctypes
ourTitle = "Greeting App"

COLLEGEOFSCRIPTING.WEEBLY.COM
ourText = "Hi Everyone"
ctypes.windll.user32.MessageBoxW(0,
ourText, ourTitle, 0)

We type our code


in the New File we made.
TYPE the code
as you see it above.
On the Next Tutorial page,
we show this code much bigger.
College of Scripting Music & Science
Christopher Topalian
user32 MessageBoxW
Greeting App X
import ctypes
Hi Everyone
ourTitle = "Greeting App"
OK

COLLEGEOFSCRIPTING.WEEBLY.COM
ourText = "Hi Everyone"
ctypes.windll.user32.MessageBoxW(0,
ourText, ourTitle, 0)
We want to create a Message box,
but we first have to import the package ctypes,
to give us access to user32 functions from windll

two lowercase L
We import the ctypes package,
which is a native built-in standard Python package.
The ctypes package allows us to use the function
MessageBoxW, from the user32 library of windll
College of Scripting Music & Science
Christopher Topalian
Save Our New File
Left Click
File Menu
*untitled* X
File
File Edit Format Run Options Window Help

COLLEGEOFSCRIPTING.WEEBLY.COM
Save Ctrl+S
Left Click
Save

We Save our File using the File Menu.


We use File Menu and choose Save File.
The Shortcut is Ctrl + S
College of Scripting Music & Science
Christopher Topalian
Naming & Saving Our Python File

COLLEGEOFSCRIPTING.WEEBLY.COM
COLLEGEOFSCRIPTING.WEEBLY.COM
Name the File
ourFirstScript.py

Left Click Save


Save Button

College of Scripting Music & Science


Christopher Topalian
Open Our File ourFirstScript.py
In the previous tutorial, we saved our file
named ourFirstScript.py on our Desktop.
Look on the Desktop for ourFirstScript.py

COLLEGEOFSCRIPTING.WEEBLY.COM
Double
Left Click
To Open

College of Scripting Music & Science


Christopher Topalian
Our Working App! ourFirstScript.py

Greeting Message X

COLLEGEOFSCRIPTING.WEEBLY.COM
i Hi Everyone

OK

As you can see above, our Python Script


works! We created a message box,
with the title of Greeting Message,
and with the text of Hi Everyone.

Next, we learn to RUN our code using F5


College of Scripting Music & Science
Christopher Topalian
Run Our Script ourFirstScript.py
Left Click
Run Menu
ourFirstScript.py – C:Users/energy/Desktop/ourFirstScript.py (3.9.1) X
File Edit Format Run
Run Options Window Help
Run Module F5

COLLEGEOFSCRIPTING.WEEBLY.COM
Left Click
Run Module

We can Run our Script using the Run Menu.


We Left Click the Run Menu and choose
Run Module. The Shortcut is F5
The Run module makes testing code easy,
but remember, the Run Module is NOT as
reliable as Double clicking to check for issues.
We Always Double Click our scripts to
ensure that they work, before sharing them
with other people.
College of Scripting Music & Science
Christopher Topalian
SetProcessDpiAwareness NiceText
import ctypes

ctypes.windll.shcore.SetProcessDpiAw
areness(1)

COLLEGEOFSCRIPTING.WEEBLY.COM
Greeting App X
ourTitle = "Greeting App" Hi Everyone
OK
ourText = "Hi Everyone"
ctypes.windll.user32.MessageBoxW(0,
ourText, ourTitle, 0)

#This makes high quality text for our interfaces.


ctypes.windll.shcore.SetProcessDpiAwareness(1)
The next page shows how the text looks with and
without the SetProcessDpiAwareness.
College of Scripting Music & Science
Christopher Topalian

SetProcessDpiAwareness NiceText
#Use this in all interface scripts for nice text
ctypes.windll.shcore.SetProcessDpiAwareness(1)
WITHOUT WITH

COLLEGEOFSCRIPTING.WEEBLY.COM
Without Dpi See how
Awareness is clear the text
NOT good. is now?
College of Scripting Music & Science
Christopher Topalian
Message Box 2 Button Choices
import ctypes Greeting App X
Ready?
ourTitle = "Greeting App"
OK Cancel

COLLEGEOFSCRIPTING.WEEBLY.COM
def ourFunction():
1 2
ourText = "Ready?"
return ourText

choice = ctypes.windll.user32.MessageBoxW(0,
ourFunction(), ourTitle, 1)
Without dpi
if (choice == 1): adjustment the
print("pressed ok") text looks bad.
Compare with
the next page.
if (choice == 2):
print("pressed cancel")
Stays open,
until user
input('Press Enter to Exit') presses Enter
College of Scripting Music & Science
Christopher Topalian
Message Box 2 Button Choices
import ctypes
ctypes.windll.shcore.SetProcessDpiAwareness(1)

ourTitle = "Greeting App" Greeting App X


Ready?

COLLEGEOFSCRIPTING.WEEBLY.COM
def ourFunction():
OK Cancel
ourText = "Ready?"
return ourText 1 2
choice = ctypes.windll.user32.MessageBoxW(0,
ourFunction(), ourTitle, 1)
Very nice text
if (choice == 1): by using
print("pressed ok") SetProcessDpi
Awareness(1)
if (choice == 2):
print("pressed cancel") Stays open,
until user
input('Press Enter to Exit') presses Enter
College of Scripting Music & Science
Christopher Topalian

SetProcessDpiAwareness NiceText
#Use this in all interface scripts for nice text
ctypes.windll.shcore.SetProcessDpiAwareness(1)

COLLEGEOFSCRIPTING.WEEBLY.COM
WITHOUT
Without Dpi
Awareness is
NOT good.

WITH
See how
clear the text
is now?

College of Scripting Music & Science


Christopher Topalian
Greeting App X
ctypes.windll.user32.
Ready? MessageBoxW(0,
OK
ourText, ourTitle, 0)

Greeting App X
ctypes.windll.user32.

COLLEGEOFSCRIPTING.WEEBLY.COM
Ready? MessageBoxW(0,
ourText, ourTitle, 1)
OK Cancel

Greeting App X
ctypes.windll.user32.
Ready? MessageBoxW(0,
Abort Retry Ignore
ourText, ourTitle, 2)

Greeting App X ctypes.windll.user32.


Ready? MessageBoxW(0,
ourText, ourTitle, 3)
Yes No Cancel
College of Scripting Music & Science
Christopher Topalian

Greeting App X
ctypes.windll.user32.
Ready?
MessageBoxW(0,
Yes No
ourText, ourTitle, 4)

COLLEGEOFSCRIPTING.WEEBLY.COM
Greeting App X
ctypes.windll.user32.
Ready? MessageBoxW(0,
ourText, ourTitle, 5)
Retry Cancel

Greeting App X
ctypes.windll.user32.
Ready? MessageBoxW(0,
ourText, ourTitle, 6)
Cancel Try Again Continue

College of Scripting Music & Science


Christopher Topalian
Message Box 3 Button Choices
import ctypes
ctypes.windll.shcore.SetProcessDpiAwareness(1)

ourTitle = "Question App" Question App X


Ready?

COLLEGEOFSCRIPTING.WEEBLY.COM
def ourFunction(): Yes No Cancel
ourText = "Ready?"
return ourText 6 7 2
choice = ctypes.windll.user32.MessageBoxW(0,
ourFunction(), ourTitle, 3)
if (choice == 6):
print("pressed Yes")
if (choice == 7):
print("pressed No")
if (choice == 2):
print("pressed Cancel")
input('Press Enter to Exit')
College of Scripting Music & Science
Christopher Topalian
Message Box 3 Button Choices
import ctypes
ctypes.windll.shcore.SetProcessDpiAwareness(1)

ourTitle = "Question App" Question App X


Ready?

COLLEGEOFSCRIPTING.WEEBLY.COM
def ourFunction(): Abort Retry Ignore
ourText = "Ready?"
return ourText 3 4 5
choice = ctypes.windll.user32.MessageBoxW(0,
ourFunction(), ourTitle, 2)
if (choice == 3):
print("pressed Abort")
if (choice == 4):
print("pressed Retry")
if (choice == 5):
print("pressed Ignore")
input('Press Enter to Exit')
College of Scripting Music & Science
Christopher Topalian
Message Box 3 Button Choices
import ctypes
ctypes.windll.shcore.SetProcessDpiAwareness(1)

ourTitle = "Question App" Question App X


Ready?

COLLEGEOFSCRIPTING.WEEBLY.COM
def ourFunction(): Cancel Try Again Continue
ourText = "Ready?"
return ourText 2 10 11
choice = ctypes.windll.user32.MessageBoxW(0,
ourFunction(), ourTitle, 6)
if (choice == 2):
print("pressed Cancel")
if (choice == 10):
print("pressed Try Again")
Learn more about
if (choice == 11): message box in the
print("pressed Continue") reference section at
input('Press Enter to Exit') the end of this book
College of Scripting Music & Science
Christopher Topalian

Python Keywords
and del import return
as elif in True
assert else is try

COLLEGEOFSCRIPTING.WEEBLY.COM
async except lambda while
await False None with
break finally nonlocal yield
class for not
continue from or
def global pass
if raise
Do NOT use these keywords
as names for your
variables, functions, or classes
College of Scripting Music & Science
abs() float() next() Christopher Topalian

all() format() object() vars()


any() frozenset() oct() zip()
ascii() getattr() open() __import__()
bin() globals() ord()
bool() hasattr() pow()
Python
breakpoint() hash() print() Built-In

COLLEGEOFSCRIPTING.WEEBLY.COM
bytearray() help() property()
bytes() hex() range() Func-
callable() id() repr() -tions
chr() input() reversed()
classmethod() int() round()
compile() isinstance() set()
complex() issubclass() setattr()
delattr() iter() slice()
dict() len() sorted()
dir() list() staticmethod()
divmod() locals() str()
enumerate() map() sum()
eval() max() super()
exec() memoryview() tuple()
filter() min() type()
College of Scripting Music & Science
Christopher Topalian

Python

COLLEGEOFSCRIPTING.WEEBLY.COM
IDLE Editor
Bigger Font Size
&
Dark Theme

College of Scripting Music & Science


Christopher Topalian
Configure IDLE
Left Click
Options
ourFirstScript.py – C:Users/energy/Desktop/ourFirstScript.py (3.9.1) X
File Edit Format Run Options
Options Window Help
Configure IDLE Left Click

COLLEGEOFSCRIPTING.WEEBLY.COM
Show Code Context Configure IDLE
Show Line Numbers
Zoom Height Alt + 2

We will Change the THEME of our Editor.


First, we Open the Options Menu.
Then we choose Configure IDLE.
We will change the Size of the Font and
we will change the Theme to DARK,
as shown on the next tutorial pages.
College of Scripting Music & Science
Christopher Topalian
Configure IDLE – Font Size

Left Click
Font/Tabs

COLLEGEOFSCRIPTING.WEEBLY.COM
Left Click
Size
Left Click
18

College of Scripting Music & Science


Christopher Topalian
Configure IDLE – DARK Theme

Left Click
Highlights

COLLEGEOFSCRIPTING.WEEBLY.COM
Left Click
IDLE Dark

Left Click
OK
OK
College of Scripting Music & Science
Christopher Topalian
DARK THEME Shown
ourFirstScript.py – C:Users/energy/Desktop/ourFirstScript.py (3.9.1) X
File Edit Format Run Options Window Help

COLLEGEOFSCRIPTING.WEEBLY.COM
The Dark Theme is very useful for long
duration coding. We recommend using the
dark theme for an easier time coding.
A bright white screen can be far too bright on
many computer monitors and TV sets.
This Dark theme also changes the Python
Shell Background, as shown on the next page.

College of Scripting Music & Science


Christopher Topalian
IDLE Shell shown as Dark Theme

COLLEGEOFSCRIPTING.WEEBLY.COM
Greeting App X

Hi Everyone

OK

The Dark Theme is much kinder to Eyes!


As you can see here, it is a calmer setting.
It's very nice when we run our scripts, that
there is not a sudden bright white screen,
that appears as the script runs.
College of Scripting Music & Science
Christopher Topalian

COLLEGEOFSCRIPTING.WEEBLY.COM
MATH

College of Scripting Music & Science


Christopher Topalian
math.pi
import math
import ctypes

ctypes.windll.shcore.SetProcessDpiAware

COLLEGEOFSCRIPTING.WEEBLY.COM
ness(1)
Value of Pi X
ourTitle = "Value of Pi" 3.141592653589793

OK
def ourFunction():
ourText = math.pi
answer = str(ourText)
return answer

ctypes.windll.user32.MessageBoxW(0,
ourFunction(), ourTitle, 0)

3.141592653589793
College of Scripting Music & Science
Christopher Topalian
math.floor
import math 4.45 becomes 4
import ctypes 4.55 becomes 4
4.95 becomes 4
ctypes.windll.shcore.SetProcessDpiAware

COLLEGEOFSCRIPTING.WEEBLY.COM
ness(1)
Floor App X

ourTitle = "Floor App" 4


OK

def ourFunction():
ourText = math.floor(4.45)
answer = str(ourText)
return answer

ctypes.windll.user32.MessageBoxW(0,
ourFunction(), ourTitle, 0)

College of Scripting Music & Science


Christopher Topalian
math.ceil
import math 4.25 becomes 5
import ctypes 4.45 becomes 5
4.55 becomes 5
ctypes.windll.shcore.SetProcessDpiAware

COLLEGEOFSCRIPTING.WEEBLY.COM
ness(1)
Ceil App X
5
ourTitle = "Ceil App"
OK

def ourFunction():
ourText = math.ceil(4.25)
answer = str(ourText)
return answer

ctypes.windll.user32.MessageBoxW(0,
ourFunction(), ourTitle, 0)

College of Scripting Music & Science


Christopher Topalian

Remember to Keep Using


SetProcessDpiAwareness(1)
for High Quality Text

COLLEGEOFSCRIPTING.WEEBLY.COM
import ctypes

ctypes.windll.shcore.SetProcessDpiAwareness(1)

In the rest of the book,


I do not add the
text quality adjustment.
But, I encourage you to use it!
It makes very nice quality text!
Use it in all of your scripts.
College of Scripting Music & Science
Christopher Topalian
round
import ctypes round to 1 place
after decimal
ourText = round(24.34, 1)
ourTitle = "Rounding App"

COLLEGEOFSCRIPTING.WEEBLY.COM
ourText = str(ourText) Convert to String

ctypes.windll.user32.MessageBoxW(0,
ourText, ourTitle, 0)
We round the decimal number 24.34
to 1 place after the decimal point.
23.34, rounds to 23.3 Rounding App X
23.35, rounds to 23.4 24.3
23.347 rounds to 23.3
OK
23.351 rounds to 23.4
College of Scripting Music & Science
Christopher Topalian
pow
import ctypes

ourText = pow(8, 2)
ourTitle = "Power of App"

COLLEGEOFSCRIPTING.WEEBLY.COM
ourText = str(ourText) Convert to String

ctypes.windll.user32.MessageBoxW(0,
ourText, ourTitle, 0)

pow means to RAISE TO THE POWER OF N


Power of App X

64

OK

College of Scripting Music & Science


Christopher Topalian
Exponents **
import ctypes

ourText = 8**2
ourTitle = "Power of App"

COLLEGEOFSCRIPTING.WEEBLY.COM
ourText = str(ourText) Convert to String

ctypes.windll.user32.MessageBoxW(0,
ourText, ourTitle, 0)
Two ** symbols are another way
to write exponents.
Power of App X

64

OK

College of Scripting Music & Science


Christopher Topalian
math.sqrt
import ctypes, math comma
to import
ourText = math.sqrt(4) multiple
ourTitle = "Square Root App" modules

COLLEGEOFSCRIPTING.WEEBLY.COM
ourText = str(ourText) Convert to String

ctypes.windll.user32.MessageBoxW(0,
ourText, ourTitle, 0)

sqrt means SQUARE ROOT


Square Root App X

2.0

OK

College of Scripting Music & Science


Christopher Topalian
CONVERT kmh to mph
import ctypes
kmh = int(input("Enter Kilometers Per Hour"))
mph = kmh * 0.6214

COLLEGEOFSCRIPTING.WEEBLY.COM
print(kmh, "Kilometers Per Hour is",
mph,"Miles Per Hour")
ourText = str(mph) + " Miles Per Hour"
ourTitle = "Kilometers per hour to mph"
ctypes.windll.user32.MessageBoxW(0,
ourText, ourTitle, 0)
input('Press Enter to Exit')
For when the user Double Clicks to open:
The last line of code, input('Press Enter to Exit')
keeps the python launcher window open,
so that the user can view the result of the choice
that they made. College of Scripting Music & Science
Christopher Topalian
Make a Function for Addition
import ctypes
def ourFunction(a, b):
c=a+b
return c

COLLEGEOFSCRIPTING.WEEBLY.COM
answer = str(ourFunction(8,8))
result = ctypes.windll.user32.MessageBoxW(0,
answer,"Addition", 0)

Addition X

i 16

OK

As you can see above, the messagebox


appears, with an info icon, and shows the result
of the addition of the two numbers 8 + 8, which
equals 16, as the result, shown as the message.
College of Scripting Music & Science
Christopher Topalian
Make a Function for Subtraction
import ctypes
def ourFunction(a, b):
c=a-b
return c

COLLEGEOFSCRIPTING.WEEBLY.COM
answer = str(ourFunction(30,20))
result = ctypes.windll.user32.MessageBoxW(0,
answer,"Subtraction", 0)

Subtraction X

i 10

OK

As you can see above, the messagebox appears,


with an info icon, and shows the result of the
subtraction of the two numbers 30 - 20, which
equals 10, as the result, shown as the message.
College of Scripting Music & Science
Christopher Topalian
Make a Function for Multiplication
import ctypes
def ourFunction(a, b):
c=a*b
return c

COLLEGEOFSCRIPTING.WEEBLY.COM
answer = str(ourFunction(4,4))
result = ctypes.windll.user32.MessageBoxW(0,
answer,"Multiplication", 0)

Multiplication X

i 16

OK

As you can see above, the messagebox appears,


with an info icon, and shows the result of the
multiplication of the two numbers 4 * 4, which
equals 16, as the result, shown as the message.
College of Scripting Music & Science
Christopher Topalian
Make a Function for Division
import ctypes
def ourFunction(a, b):
c=a/b
return c

COLLEGEOFSCRIPTING.WEEBLY.COM
answer = str(ourFunction(16,4))
result = ctypes.windll.user32.MessageBoxW(0,
answer,"Division", 0)

Division X

i 4.0

OK

As you can see above, the messagebox appears,


with an info icon, and shows the result of the
division of the two numbers 16 / 4, which equals
4.0, as the result, shown as the message.
College of Scripting Music & Science
Christopher Topalian

MAKE AN

COLLEGEOFSCRIPTING.WEEBLY.COM
APP
WINDOW

College of Scripting Music & Science


Christopher Topalian
New Blank Window
Make Window Object
from tkinter import *
height y pos
ourWindow = Tk() width x pos

COLLEGEOFSCRIPTING.WEEBLY.COM
ourWindow.geometry('500x300+300+200')

ourWindow.title('A Simple Window')

ourWindow.mainloop() Run Event Loop

We can make a window and populate it with


graphical user interface elements, such as
labels and buttons, and we can fill our
window with text, images, and even videos.
geometry specifies the window size and
location on the screen.
mainloop() handles all events.
College of Scripting Music & Science
Christopher Topalian
New Window, Button Changes Color
from tkinter import *
def ourFunction():
print('Blue')
ourWindow.configure(bg='blue')

COLLEGEOFSCRIPTING.WEEBLY.COM
ourWindow = Tk()
ourWindow.geometry('300x200+300+200')
ourWindow.title('Here is Our Window')
ourButton = Button(ourWindow,
text = 'Change Color',
command = ourFunction,
fg = 'white', bg = 'black').place(x = 100, y = 50)
ourWindow.mainloop()

This script makes a Window, with a Button that


changes the Background Color of the Window.
College of Scripting Music & Science
Christopher Topalian
New Window, font size, font type
from tkinter import * y pos
height
ourWindow = Tk() width x pos

ourWindow.geometry('700x400+300+150')

COLLEGEOFSCRIPTING.WEEBLY.COM
ourWindow.title('Our Window')
ourLabel = Label(ourWindow,
text = 'This is Fun', width = '200',
font=("Courier", 25), fg = 'aqua',
bg = 'black').pack()
ourWindow.mainloop()

We make a Window with a Label width of 200,


with a black background, aqua font color and
Courier font face that is 25 for the font size.
College of Scripting Music & Science
Christopher Topalian
New Window, font size/type variable
from tkinter import * height y pos
width x pos
ourWindow = Tk()
ourWindow.geometry('500x400+300+150')
ourWindow.title('Our New Window')

COLLEGEOFSCRIPTING.WEEBLY.COM
ourText = 'Hi Everyone'
ourFontSize = 22
ourFontStyle = "Arial"
ourLabel = Label(ourWindow,
text = ourText, width = '10',
font=(ourFontStyle, ourFontSize),
fg = 'aqua', bg = 'black').pack(side = LEFT)
ourWindow.mainloop()
We make a Window with a Label width of 10,
a black background, aqua font color, Arial font
face, 22 for the font size, placed with pack
LEFT, places object on left side of window.
College of Scripting Music & Science
Christopher Topalian
New Window Labels Placed
from tkinter import * height y pos
width x pos
ourWindow = Tk()
ourWindow.geometry('400x200+200+100')

COLLEGEOFSCRIPTING.WEEBLY.COM
ourWindow.title('Greeter')

ourFirstLabel = Label(ourWindow,
text = 'Hi There',
fg = 'aqua', bg = 'black').place(x = 75, y = 75)

ourSecondLabel = Label(ourWindow,
text = 'Happy Scripting',
fg = 'aqua', bg = 'black').place(x = 75, y = 115)

ourWindow.mainloop()
We make a window, with a title of Greeter,
and style two labels, that are placed in our
window at specified locations of x and y.
College of Scripting Music & Science
Christopher Topalian
New Window Labels Grid Sticky
from tkinter import * height y pos
width x pos
ourWindow = Tk()
ourWindow.geometry('400x200+200+100')

COLLEGEOFSCRIPTING.WEEBLY.COM
ourWindow.title('Greeter')

ourLabel1 = Label(ourWindow,
text = 'Hi Everyone', fg = 'aqua',
bg = 'black').grid(row = 0, column = 0, sticky = W)

ourLabel2 = Label(ourWindow,
text = 'Happy Scripting', fg = 'black',
bg = 'aqua').grid(row = 0, column = 1, sticky = W)

ourWindow.mainloop()

We make a window, with a title of Greeter, and


style two labels, that are placed in our window
using grid function and sticky options.
College of Scripting Music & Science
Christopher Topalian
New Window Labels Button
from tkinter import *
def ourNewLabel():
ourLabel3 = Label(ourWindow, text = 'Hi Everyone',
fg = 'blue').grid(row = 3, column = 0, sticky = W)
return

COLLEGEOFSCRIPTING.WEEBLY.COM
ourWindow = Tk()
ourWindow.geometry('400x200+200+100')
ourWindow.title('Our Window')
ourLabel1 = Label(ourWindow,
text = 'Howdy', fg = 'aqua',
bg = 'black').grid(row = 0, column = 0, sticky = W)
ourLabel2 = Label(ourWindow,
text = 'How are you?', fg = 'black',
bg = 'aqua').grid(row = 0, column = 1, sticky = W)
ourButton1 = Button(ourWindow,
text = 'Click Here', command = ourNewLabel,
fg = 'white', bg = 'black').grid(row = 1, column = 0,
sticky = W)
ourWindow.mainloop() College of Scripting Music & Science
Christopher Topalian
New Window, while, counts 5 Rows
import time height y pos
from tkinter import * width
x pos
ourWindow = Tk()
ourWindow.geometry('275x210+200+150')
ourWindow.title('Greeting App')

COLLEGEOFSCRIPTING.WEEBLY.COM
ourTitle = "Visitor Counter"
ourText = "People"
counter = 0
x=1
while x <= 5:
counter += 1
ourMessage = str(counter) + ' ' + ourText
x = x + 1;
ourLabel = Label(ourWindow,
text = ourMessage, width = '200', Next page
font=("Courier", 25), fg = 'aqua', shows a
bg = 'black').pack() slight
ourWindow.mainloop() variation
College of Scripting Music & Science
Christopher Topalian
New Window, while, counts 5 Rows
import time height y pos
from tkinter import * width x pos
ourWindow = Tk()
ourWindow.geometry('275x125+200+150')
ourWindow.title('Greeting App')

COLLEGEOFSCRIPTING.WEEBLY.COM
ourTitle = "Visitor Counter"
ourText = "People"
x=1
while x <= 3:
ourMessage = str(x) + ' ' + ourText
x = x + 1; x is used
ourLabel = Label(ourWindow, as the
text = ourMessage, width = '200', counting
font=("Courier", 25), fg = 'aqua', variable
bg = 'black').pack()
ourWindow.mainloop()

This script is a slight variation of the previous page.


College of Scripting Music & Science
Christopher Topalian
New Window, Button Counts Up
from tkinter import*
count = 0
def ourCounter():
global count

COLLEGEOFSCRIPTING.WEEBLY.COM
count = count + 1
ourLabel1.configure(text=f'Button Clicks {count}')
ourWindow = Tk()
ourWindow.geometry('300x125+200+150')
ourWindow.title("Counts Up")
ourLabel1 = Label(ourWindow, font=("Arial", 25))
ourLabel1.pack()
ourButton = Button(ourWindow, text="Press",
command=ourCounter, font=("Arial", 25))
ourButton.pack()
ourWindow.mainloop()

College of Scripting Music & Science


Christopher Topalian

COLLEGEOFSCRIPTING.WEEBLY.COM
Text Field
for
User Input

College of Scripting Music & Science


Christopher Topalian
Text Input Field - Entry, pack
from tkinter import *
ourWindow = Tk() Hi Everyone

ourTextField1 = Entry(ourWindow) ENTER


ourTextField1.pack() Hi Everyone

COLLEGEOFSCRIPTING.WEEBLY.COM
def ourFunction():
textEntered = ourTextField1.get()
ourLabel = Label(ourWindow,
text = textEntered, fg = 'aqua', bg = 'black').pack()
ourButton = Button(ourWindow, text = "ENTER",
command = ourFunction).pack()
ourWindow.mainloop()

Entry is how we make Text Input Boxes for


users to type in their information.
In this example, we place the Text Boxes
using the pack() method, which positions
elements in relation to one another.
College of Scripting Music & Science
Christopher Topalian
Text Input Field - Entry, place
from tkinter import *
ourWindow = Tk()
Hi Everyone

ourTextField1 = Entry(ourWindow)
ENTER
ourTextField1.place(x=40, y=35)

COLLEGEOFSCRIPTING.WEEBLY.COM
Hi Everyone
def ourFunction():
textEntered = ourTextField1.get()
ourLabel = Label(ourWindow,
text = textEntered, fg = 'aqua', bg = 'black')
ourLabel.place(x = 50, y = 115)
ourLabel.width=200
ourLabel.height=10
ourButton = Button(ourWindow, text = "ENTER",
command = ourFunction)
ourButton.width=15
ourButton.height=10
ourButton.place(x=50,y=75)
ourWindow.mainloop()

College of Scripting Music & Science


Text Input Field - Entry - bgChristopher
Color Topalian

from tkinter import *


ourWindow = Tk()
blue
ourTextField1 = Entry(ourWindow)
ourTextField1.place(x=40, y=35) ENTER

def ourFunction(): blue

COLLEGEOFSCRIPTING.WEEBLY.COM
textEntered = ourTextField1.get()
if(textEntered == 'blue'):
ourWindow.configure(bg='blue')
elif(textEntered=='tan'):
ourWindow.configure(bg='tan')
ourLabel = Label(ourWindow,
text = textEntered, fg = 'aqua', bg = 'black')
ourLabel.place(x = 50, y = 115)
ourLabel.width=200
ourLabel.height=10
ourButton = Button(ourWindow, text = "ENTER",
command = ourFunction)
ourButton.width=15
ourButton.height=10
ourButton.place(x=50,y=75)
ourWindow.mainloop() College of Scripting Music & Science
Textbox Updates Label byChristopher
Typing Topalian

from tkinter import * height y pos


width x pos
ourWindow = Tk()
ourWindow.geometry('275x75+200+150')
ourWindow.title('Textbox to Label')

COLLEGEOFSCRIPTING.WEEBLY.COM
ourVariable = StringVar()

ourVariable.set('Hi Everyone')

ourLabel1 = Label(ourWindow,
textvariable = ourVariable)
ourLabel1.pack()

ourTextArea = Entry(ourWindow,
textvariable = ourVariable)
Textbox to Label _ □ X
ourTextArea.pack()
Hi Everyone
ourWindow.mainloop() Hi Everyone

College of Scripting Music & Science


Christopher Topalian
Textbox - Two Updated Labels,Typing
from tkinter import *
ourWindow = Tk()
ourWindow.geometry('275x100+200+150')
ourWindow.title('Textbox to Label')
ourVariable1 = StringVar()
ourVariable1.set('First Name') _□X

COLLEGEOFSCRIPTING.WEEBLY.COM
Textbox to Label
ourLabel1 = Label(ourWindow, Hi
First
Everyone
Name
textvariable = ourVariable1) Hi Everyone
First Name
ourLabel1.pack()
Last Name
ourTextArea = Entry(ourWindow,
textvariable = ourVariable1) Last Name
ourTextArea.pack()
#-----------------------------------------------
ourVariable2 = StringVar()
ourVariable2.set('Last Name')
ourLabel2 = Label(ourWindow,
textvariable = ourVariable2)
ourLabel2.pack()
ourTextArea2 = Entry(ourWindow,
textvariable = ourVariable2)
ourTextArea2.pack()
ourWindow.mainloop() College of Scripting Music & Science
Christopher Topalian

COLLEGEOFSCRIPTING.WEEBLY.COM
timers

College of Scripting Music & Science


Christopher Topalian
Timer - Activates One Time
import time
time.sleep(4.0)
print('4 seconds passed')

COLLEGEOFSCRIPTING.WEEBLY.COM
input('Press Enter to Exit')
IDLE Shell 3.9.1 X
File Edit Format Run Options Window Help

The text shown says:


4 seconds passed

College of Scripting Music & Science


Christopher Topalian
Timer – Keep Activating
import time

x=0

COLLEGEOFSCRIPTING.WEEBLY.COM
while x != 1:
time.sleep(4.0)
print('4 seconds passed')

input('Press Enter to Exit')

sleep function is found in the time module,


which is why we import time
In this example, our Message is created every
4 seconds.
College of Scripting Music & Science
Christopher Topalian
Timer - Activates One Time
Greeting Timer X
import time, ctypes
Hi Everyone
ourTitle = "Greeting Timer"
ourText = "Hi Everyone" OK

COLLEGEOFSCRIPTING.WEEBLY.COM
time.sleep(4.0)
ctypes.windll.user32.MessageBoxW(0,
ourText, ourTitle, 0)

sleep function is found in the time module,


which is why we import time
In this example, our Message Box is created
ONLY once, after a 4 second sleep.
On the next page, we make a repeating timer,
to keep activating, a specified number of times.
College of Scripting Music & Science
Christopher Topalian
Timer - Keep Activating, while
import time, ctypes Greeting Timer X

ourTitle = "Greeting Timer" Hi Everyone


ourText = "Hi Everyone"
OK

COLLEGEOFSCRIPTING.WEEBLY.COM
x=1
while x <= 5:
time.sleep(2.0)
x = x + 1;
ctypes.windll.user32.MessageBoxW(0,
ourText, ourTitle, 0)

Our Message Box is created, and after the user


presses OK, 2 seconds passes, and another
Message Box is created, with a max number of
5 Message Boxes allowed. The while loop is
where we specify how many times we want our
timer to activate.
College of Scripting Music & Science
Christopher Topalian
Timer - Keep Activating, counter
import time, ctypes Visitor Counter X

ourTitle = "Visitor Counter" 5 People


ourText = "People" OK

COLLEGEOFSCRIPTING.WEEBLY.COM
counter = 0
x=1
while x <= 5:
time.sleep(2.0)
counter += 1
ourMessage = str(counter) + ' ' + ourText
x = x + 1;
ctypes.windll.user32.MessageBoxW(0,
ourMessage, ourTitle, 0)

Our Message Box, with a counter, counts to 5


College of Scripting Music & Science
Christopher Topalian
timer, Window, while, font styling
import time
from tkinter import * height y pos
width x pos
ourWindow = Tk()
ourWindow.geometry('300x200+200+150')

COLLEGEOFSCRIPTING.WEEBLY.COM
ourWindow.title('Greeting App')
time.sleep(60.0)
ourLabel = Label(ourWindow,
text = 'This is Fun', width = '200',
font=("Courier", 25), fg = 'aqua',
bg = 'black').pack()
ourWindow.mainloop()
This Script is a 1 Minute Timer, that will
open your Application Window, 60 seconds
after you choose to Run it.
College of Scripting Music & Science
Christopher Topalian

COLLEGEOFSCRIPTING.WEEBLY.COM
Clock

College of Scripting Music & Science


Christopher Topalian
Clock Updates
from tkinter import *
height y pos
from time import*
width x pos
ourWindow = Tk()
ourWindow.geometry('400x50+200+150')

COLLEGEOFSCRIPTING.WEEBLY.COM
ourWindow.title('Keep Updating Clock')
def ourFunction():
theTime = localtime()
formattedTime = asctime(theTime)
ourText.set(formattedTime)
ourLabel1.after(1000, ourFunction)
ourText = StringVar()
ourText.set('Click for Time')
ourLabel1 = Label(ourWindow,
textvariable = ourText, font=("Arial", 25))
ourLabel1.pack() Textbox
Keep to Label
Updating Clock
_ □ X

ourFunction() Sat Apr 10Hi09:08:49


Everyone 2021
ourWindow.mainloop()
College of Scripting Music & Science
Christopher Topalian
Clock Updates After Button Press
from tkinter import * height y pos
from time import*
width x pos
ourWindow = Tk()
ourWindow.geometry('500x100+200+150')
ourWindow.title('Keep Updating Clock')

COLLEGEOFSCRIPTING.WEEBLY.COM
def ourFunction():
theTime = localtime()
formattedTime = asctime(theTime)
ourText.set(formattedTime)
ourLabel1.after(1000, ourFunction)
_ □ X
ourText = StringVar() Textbox
Keep to Label
Updating Clock

ourText.set('Click for Time') Sat Apr Hi


10Everyone
09:08:49 2021
HiPress
Everyone
ourLabel1 = Label(ourWindow,
textvariable = ourText, font=("Arial", 25))
ourLabel1.pack()
ourButton = Button(ourWindow, text="Press",
command=ourFunction, font=("Arial", 25))
ourButton.pack()
ourWindow.mainloop()
College of Scripting Music & Science
Christopher Topalian
Clock Updates in Seconds
from tkinter import *
from time import* height y pos
width x pos
ourWindow = Tk()
ourWindow.geometry("200x50+60+600")

COLLEGEOFSCRIPTING.WEEBLY.COM
ourWindow.title("Clock Updating")
def ourClock():
formatted = strftime('%H:%M:%S %p')
currentTime.config(text = formatted)
ourWindow.after(1000, ourClock)
currentTime= Label(text='',
bg="black",fg="white", font=("Arial", 25))
currentTime.pack()
ourClock()
ourWindow.mainloop()
College of Scripting Music & Science
Christopher Topalian
Clock Updates in Seconds
from tkinter import *
from time import* height y pos
width x pos
ourWindow = Tk()
ourWindow.geometry('300x75+200+150')

COLLEGEOFSCRIPTING.WEEBLY.COM
ourWindow.title('Updating Clock')
def ourClock():
formatted = strftime('%H:%M:%S %p')
ourWindow.config(text = formatted)
ourWindow.after(1000, ourClock)
ourWindow = Label(ourWindow,
font = ('arial', 35, 'bold'),
bg = 'black', fg = 'white')
ourWindow.pack(fill="none", expand=True)
ourClock()
ourWindow.mainloop()
College of Scripting Music & Science
Clock – Alarm Clock - Christopher
BeepTopalian
from tkinter import *
from time import*
import winsound
ourWindow = Tk()
ourWindow.geometry('300x75+200+150')

COLLEGEOFSCRIPTING.WEEBLY.COM
ourWindow.title('Alarm Clock')
def ourClock():
formatted = strftime('%H:%M:%S %p')
ourWindow.config(text = formatted)
ourWindow.after(1000, ourClock)
Pitch is
if(formatted > '13:44:10PM'): 0 to 2500 Hz
print('Alarm Activated') Length is in
winsound.Beep(1000,500) milli seconds
ourWindow.configure(bg='blue')
ourWindow = Label(ourWindow,
font = ('arial', 35, 'bold'),
bg = 'black', fg = 'white')
ourWindow.pack(fill="none", expand=True)
ourClock()
ourWindow.mainloop() College of Scripting Music & Science
Clock – Alarm Clock - PlaySound
Christopher Topalian

from tkinter import *


from time import*
import winsound
ourWindow = Tk()
ourWindow.geometry('300x75+200+150')

COLLEGEOFSCRIPTING.WEEBLY.COM
ourWindow.title('Alarm Clock')
def ourClock():
formatted = strftime('%H:%M:%S %p')
ourWindow.config(text = formatted)
ourWindow.after(1000, ourClock)
if(formatted > '13:44:10PM'):
print('Alarm Activated')
winsound. PlaySound('MB_ICONASTERISK', True)
ourWindow.configure(bg='blue')
ourWindow = Label(ourWindow,
font = ('arial', 35, 'bold'),
bg = 'black', fg = 'white')
ourWindow.pack(fill="none", expand=True)
ourClock()
ourWindow.mainloop()
College of Scripting Music & Science
Clock – Alarm Clock - PlaySound
Christopher Topalian

from tkinter import *


from time import*
import winsound
ourWindow = Tk()
ourWindow.geometry('725x75+200+150')

COLLEGEOFSCRIPTING.WEEBLY.COM
ourWindow.title('Alarm Clock')
def ourClock():
theTime = localtime()
formatted = asctime(theTime)
ourWindow.config(text = formatted)
ourWindow.after(1000, ourClock)
if(formatted > '13:44:10PM'):
print('Alarm Activated')
winsound. PlaySound('MB_ICONASTERISK', True)
ourWindow.configure(bg='blue')
ourWindow = Label(ourWindow,
font = ('arial', 35, 'bold'),
bg = 'black', fg = 'white')
ourWindow.pack(fill="none", expand=True)
ourClock()
ourWindow.mainloop()
College of Scripting Music & Science
Alarm Clock – with Start Christopher
and End Topalian

from tkinter import *


from time import* height y pos
import winsound width x pos
ourWindow = Tk()
ourWindow.geometry('300x75+200+150')
ourWindow.title('Alarm Clock')

COLLEGEOFSCRIPTING.WEEBLY.COM
start = '19:50:00PM'
end = '19:50:10PM'
def ourClock():
formatted = strftime('%H:%M:%S %p')
ourWindow.config(text = formatted)
ourWindow.after(1000, ourClock)
if(formatted > start and formatted < end):
print('Alarm Activated')
winsound.PlaySound('MB_ICONASTERISK', True)
ourWindow.configure(bg='blue')
ourWindow = Label(ourWindow,
font = ('arial', 35, 'bold'),
bg = 'black', fg = 'white')
ourWindow.pack(fill="none", expand=True)
ourClock()
ourWindow.mainloop() College of Scripting Music & Science
Christopher Topalian

COLLEGEOFSCRIPTING.WEEBLY.COM
Counter

College of Scripting Music & Science


Christopher Topalian
Counts Up – 0 to 10
from tkinter import *
height y pos
from time import*
width x pos
ourWindow = Tk()
ourWindow.geometry('300x75+200+150')
ourWindow.title('Counts 0 to 10')

COLLEGEOFSCRIPTING.WEEBLY.COM
count = 0
def ourCounter():
global count
if(count != 10):
count += 1
ourWindow.config(text = count)
ourWindow.after(1000, ourCounter)
ourWindow = Label(ourWindow,
font = ('arial', 35, 'bold'),
bg = 'black', fg = 'white')
ourWindow.pack(fill="none", expand=True)
ourCounter()
ourWindow.mainloop()College of Scripting Music & Science
Christopher Topalian
Counts Down – 10 to 0
from tkinter import * height y pos
from time import* width x pos
ourWindow = Tk()
ourWindow.geometry('300x75+200+150')

COLLEGEOFSCRIPTING.WEEBLY.COM
ourWindow.title('Counts 10 to 0')
count = 11
def ourCounter():
global count
if(count != 0):
count -= 1
ourWindow.config(text = count)
ourWindow.after(1000, ourCounter)
ourWindow = Label(ourWindow,
font = ('arial', 35, 'bold'),
bg = 'black', fg = 'white')
ourWindow.pack(fill="none", expand=True)
ourCounter()
ourWindow.mainloop()College of Scripting Music & Science
Christopher Topalian
Counts Up – Specified Amount
from tkinter import * height y pos
from time import* width x pos
ourWindow = Tk()
ourWindow.geometry('300x75+200+150')
ourWindow.title('Count Up by Amount')

COLLEGEOFSCRIPTING.WEEBLY.COM
count = 0
def ourCounter(seconds):
global count
if(count != seconds):
count += 1
ourWindow.config(text = count)
ourWindow.after(1000, ourCounter, seconds)
ourWindow = Label(ourWindow,
font = ('arial', 35, 'bold'),
bg = 'black', fg = 'white')
ourWindow.pack(fill="none", expand=True)
ourCounter(60)
ourWindow.mainloop()
College of Scripting Music & Science
Christopher Topalian

COLLEGEOFSCRIPTING.WEEBLY.COM
Button

College of Scripting Music & Science


Button Updates Label onChristopher
PressTopalian
from tkinter import * height y pos
width x pos
ourWindow = Tk()
ourWindow.geometry('275x100+200+150')
ourWindow.title('Button Updates Label')

COLLEGEOFSCRIPTING.WEEBLY.COM
Textbox
Button Label _ □ X
to Label
Updates
def ourFunction():
ourVariable1.set('howdy') HiHiEveryone
Everyone
Hi Everyone
ourVariable1 = StringVar()
Press
ourVariable1.set('Hi Everyone')
Textbox
Button Label _ □ X
to Label
Updates
ourLabel1 = Label(ourWindow, HiHowdy
Everyone
textvariable = ourVariable1) Hi Everyone
ourLabel1.pack() Press

ourButton = Button(ourWindow, text="Press",


command=ourFunction, font=("Arial", 25))
ourButton.pack()
ourWindow.mainloop()
College of Scripting Music & Science
Button – Toggle Switch – Christopher
On, Off Topalian

from tkinter import *


ourWindow = Tk()
ourWindow.geometry('275x100+200+150')
ourWindow.title('Button Toggle Switch')
on = False
Switch _ □X

COLLEGEOFSCRIPTING.WEEBLY.COM
Textbox
Button to Label
Toggle
def ourFunction():
global on HiHiEveryone
Everyone
default Hi Everyone
if(on == False): Press
ourVariable1.set('On')
on = True Textbox
Button Switch _
to Label
Toggle □X
elif(on == True): Hi Everyone
On
ourVariable1.set('Off') 1st
Click Hi Everyone
on = False Press
ourVariable1 = StringVar() _ □X
ourVariable1.set('Hi Everyone') Textbox
Button to Label
Toggle Switch
Hi Everyone
Off
ourLabel1 = Label(ourWindow, 2nd
Click Hi Everyone
textvariable = ourVariable1) Press
ourLabel1.pack()
ourButton = Button(ourWindow, text="Press",
command=ourFunction, font=("Arial", 25))
ourButton.pack()
ourWindow.mainloop()
College of Scripting Music & Science
Button – Toggle Switch withChristopher
BeepsTopalian
from tkinter import *
import winsound
ourWindow = Tk()
ourWindow.geometry('275x100+200+150')
ourWindow.title('Button Toggle Switch')
on = False
Switch _ □ X

COLLEGEOFSCRIPTING.WEEBLY.COM
def ourFunction(): Textbox
Button to Label
Toggle
global on HiHiEveryone
Everyone
if(on == False): default Hi Everyone
ourVariable1.set('on')
Press
winsound.Beep(1000,100)
on = True Textbox
Button Toggle Switch _ □ X
to Label
elif(on == True): 1st Hi Everyone
On
ourVariable1.set('off') Click Hi Everyone beep
winsound.Beep(500,100)
Press high
on = False
Textbox
Button Switch _ □ X
to Label
Toggle
ourVariable1 = StringVar()
2nd Hi Everyone
Off
ourVariable1.set('Hi Everyone')
Click Hi Everyone
ourLabel1 = Label(ourWindow, Press beep
textvariable = ourVariable1) low
ourLabel1.pack()
ourButton = Button(ourWindow, text="Press",
command=ourFunction, font=("Arial", 25))
ourButton.pack()
ourWindow.mainloop() College of Scripting Music & Science
Button Counts Up byChristopher
1 Topalian

from tkinter import *


ourWindow = Tk()
ourWindow.geometry('275x100+200+150')
ourWindow.title('Button Counts Up by 1')

COLLEGEOFSCRIPTING.WEEBLY.COM
counter = 0
def countUp():
global counter
counter += 1
ourVariable1.set('Number of Clicks ' + str(counter))
ourVariable1 = StringVar()
Textbox
Button Up by 1 _ □ X
to Label
Counts
ourVariable1.set('Hi Everyone')
Number
Hi Everyone
of Clicks 17
ourLabel1 = Label(ourWindow, Hi Everyone
textvariable = ourVariable1) Press
ourLabel1.pack()
ourButton = Button(ourWindow, text="Press",
command=countUp, font=("Arial", 25))
ourButton.pack()
ourWindow.mainloop()
College of Scripting Music & Science
Christopher Topalian
Button Counts Down by 1
from tkinter import *
ourWindow = Tk()
ourWindow.geometry('275x100+200+150')
ourWindow.title('Button Counts Down')

COLLEGEOFSCRIPTING.WEEBLY.COM
counter = 100
def countDown():
global counter
counter -= 1
ourVariable1.set('Number of Clicks ' + str(counter))
ourVariable1 = StringVar() _ □X
Textbox
Button to Label
Counts Down
ourVariable1.set('Hi Everyone')
Number
Hi Everyone
of Clicks 17
ourLabel1 = Label(ourWindow, Hi Everyone
textvariable = ourVariable1) Press
ourLabel1.pack()
ourButton = Button(ourWindow, text="Press",
command=countDown, font=("Arial", 25))
ourButton.pack()
ourWindow.mainloop()
College of Scripting Music & Science
Button Counts Up to 10, Christopher
resetsTopalian
from tkinter import *
ourWindow = Tk()
ourWindow.geometry('275x100+200+150')
ourWindow.title('Button Counts Up')
counter = 0

COLLEGEOFSCRIPTING.WEEBLY.COM
def ourFunction():
global counter
counter += 1
ourVariable1.set('Number of Clicks ' + str(counter))
if(counter == 10):
ourVariable1.set('Counter Reset')
counter = 0
ourVariable1 = StringVar() Textbox
Button to Label
Counts Up _ □X

ourVariable1.set('Hi Everyone') Counter


Hi Everyone
Reset
Hi Everyone
ourLabel1 = Label(ourWindow, Press
textvariable = ourVariable1)
ourLabel1.pack()
ourButton = Button(ourWindow, text="Press",
command=ourFunction, font=("Arial", 25))
ourButton.pack()
ourWindow.mainloop() College of Scripting Music & Science
Button Counts Down to 0,Christopher
resets Topalian

from tkinter import *


ourWindow = Tk()
ourWindow.geometry('275x100+200+150')
ourWindow.title('Button Counts Down')
counter = 10

COLLEGEOFSCRIPTING.WEEBLY.COM
def ourFunction():
global counter
counter -= 1
ourVariable1.set('Number of Clicks ' + str(counter))
if(counter == 0):
ourVariable1.set('Counter Reset')
counter = 10
ourVariable1 = StringVar() Button Counts
Textbox Down _ □ X
to Label
ourVariable1.set('Hi Everyone') Hi Everyone
Counter Reset
Hi Everyone
ourLabel1 = Label(ourWindow, Press
textvariable = ourVariable1)
ourLabel1.pack()
ourButton = Button(ourWindow, text="Press",
command=ourFunction, font=("Arial", 25))
ourButton.pack()
ourWindow.mainloop() College of Scripting Music & Science
Christopher Topalian
from tkinter import *
ourWindow = Tk()
ourWindow.geometry('275x100+200+150')
Button
ourWindow.title('Button Counter') Count Up
counter = 0 Count Down
def countUp():
global counter
counter += 1

COLLEGEOFSCRIPTING.WEEBLY.COM
ourVariable1.set('Number of Clicks ' + str(counter))
def countDown():
global counter
counter -= 1
ourVariable1.set('Number of Clicks ' + str(counter))
ourVariable1 = StringVar()
Textbox to Label _ □X
ourVariable1.set('Number of Clicks') Button Counter
Counter
Hi Everyone
Reset
ourLabel1 = Label(ourWindow,
Hi Everyone
textvariable = ourVariable1) Down Up
ourLabel1.pack()
downButton = Button(ourWindow, text="Down",
command=countDown, font=("Arial", 25))
downButton.pack(side=LEFT)
upButton = Button(ourWindow, text="Up",
command=countUp, font=("Arial", 25))
upButton.pack(side=LEFT)
ourWindow.mainloop() College of Scripting Music & Science
Christopher Topalian

COLLEGEOFSCRIPTING.WEEBLY.COM
OS

College of Scripting Music & Science


Christopher Topalian
Create a Text File
ourFile = open("testFile.txt", "w")
ourFile.write("Hi Everyone")
ourFile.close()

COLLEGEOFSCRIPTING.WEEBLY.COM
Creates a TXT file in the same
folder that ourScript.py is in

College of Scripting Music & Science


Christopher Topalian
Open a File (in same folder)
import os
os.startfile('testFile.txt')

COLLEGEOFSCRIPTING.WEEBLY.COM
Both files are in
SAME Folder!

College of Scripting Music & Science


Christopher Topalian
Open a File (from any Folder)
import os

os.startfile('C:/Users/you/Desktop/testFile.txt')

COLLEGEOFSCRIPTING.WEEBLY.COM
testFile.txt
is located
on our
Desktop!

College of Scripting Music & Science


Christopher Topalian
Create a Text File - Long Line
ourText = 'This long line of text \
will be shown as one line. \
We use the backslash \

COLLEGEOFSCRIPTING.WEEBLY.COM
to accomplish this.'
ourFile = open('testFile.txt', 'w')
ourFile.write(ourText)
ourFile.close()
We write ONE long line of text into the text file.
If text file doesn't exist yet, it is created.
If text file already exists, w means overwrite it.

College of Scripting Music & Science


Christopher Topalian
Create a Text File - Multi Line
ourText = 'When coding in Python,\n\
we can make multiple lines \
of text very easily. \n\
We use backslash n to allow the \

COLLEGEOFSCRIPTING.WEEBLY.COM
multi line style.'
ourFile = open('testFile.txt', 'w')
ourFile.write(ourText)
ourFile.close() w a
writes/ appends
overwrites at end

College of Scripting Music & Science


Christopher Topalian
Read a Text File, for loop messages
import ctypes
here = open('C:/Users/you/Desktop/testFile.txt')
for x in here:

COLLEGEOFSCRIPTING.WEEBLY.COM
ctypes.windll.user32.MessageBoxW(0,
x, "The Title", 0)

The Title X

This is line one

OK

Here is the
testFile.txt is located MessageBox that
on our Desktop and shows each line,
has 7 lines of text one by one.
College of Scripting Music & Science
Christopher Topalian
Read Text File, Make Labels in Window
from tkinter import * height y pos
width x pos
ourWindow = Tk()
ourWindow.geometry('400x300+200+100')
ourWindow.title('Howdy')

COLLEGEOFSCRIPTING.WEEBLY.COM
text = open('C:/Users/energy/Desktop/testFile.txt')
x = 75
y=5
for z in text:
ourFirstLabel = Label(ourWindow,
text = z, fg = 'aqua',
bg = 'black').place(x = x, y = y)
y += 40
ourWindow.mainloop()

We read a text file, that has multiple lines of text.


Each line of text becomes a label, that is
positioned, evenly spaced, in our window.
College of Scripting Music & Science
Christopher Topalian

When placed
in Any Folder
and Activated,

COLLEGEOFSCRIPTING.WEEBLY.COM
this next script
shows the
Full Path Names
of All Files
in the Folder
and Subfolders
College of Scripting Music & Science
Christopher Topalian
Show File Path Names of Files in the Folder
that this script is Run in
import os
path = os.path.dirname(os.path.realpath(__file__))
theFiles = [ ]

COLLEGEOFSCRIPTING.WEEBLY.COM
two underscore
for folder, subfolder, ourFiles in os.walk(path):
for file in ourFiles:
theFiles.append(os.path.join(folder,file))

for theName in theFiles:


print(theName)

input('Press Enter to Exit')

folder, means any folder we place this script in


subfolder, means any subfolders in the folder
ourFiles, means any files in folder & subfolders
College of Scripting Music & Science
Christopher Topalian
Show File Path Names of Files in the Folder
import os by extension type
path = os.path.dirname(os.path.realpath(__file__))
for folder, subfolder, ourFiles in os.walk(path):

COLLEGEOFSCRIPTING.WEEBLY.COM
for file in ourFiles:
if(file.endswith(".jpg")):
print(os.path.join(folder,file))
input('Press Enter to Exit')

When this script is placed in any Folder and


Run, it shows the full path names of the files
in that folder and its subfolders, that have the
extension .jpg
We specify any file type that we want, such
as .txt, .ods, .odt, .pdf, .gif, .png or other.
We can also specify more extension types to
show, by using the or operator, as shown on
the next page.
College of Scripting Music & Science
Christopher Topalian
Show File Path Names of Files in the Folder
import os by extension types
path = os.path.dirname(os.path.realpath(__file__))
for folder, subfolder, ourFiles in os.walk(path):

COLLEGEOFSCRIPTING.WEEBLY.COM
for file in ourFiles:
if(file.endswith(".gif") or file.endswith(".jpg")):
print(os.path.join(folder,file))
input('Press Enter to Exit')

When this script is placed in any Folder and


Run, it shows the full path names of the files
in that folder and its subfolders, that have the
extension .gif or .jpg
We may specify as many file types as we want.
We use the or operator as shown below, to
specify multiple extension types.
if(file.endswith(".gif") or file.endswith(".jpg") or
file.endswith(".bmp") or file.endswith(".tiff")):
College of Scripting Music & Science
Christopher Topalian
Show File Path Names, Write to Text File
import os with line breaks
path = os.path.dirname(os.path.realpath(__file__))
theFiles = [ ]

COLLEGEOFSCRIPTING.WEEBLY.COM
for folder, subfolder, ourFiles in os.walk(path):
for file in ourFiles:
theFiles.append(os.path.join(folder,file))
with open('testFile.txt', 'w') as ourNewFile:
for item in theFiles:
ourNewFile.write("%s\n" % item)
print("\n".join(theFiles))
input('Press Enter to Exit')
When this script is placed in any Folder and
Run, it shows the full path names of the files
in that folder and its subfolders and creates
a TEXT FILE with those full path names
shown on new lines. College of Scripting Music & Science
Christopher Topalian

This next script


shows the

COLLEGEOFSCRIPTING.WEEBLY.COM
File Path Names
of the Files
in Any Folder that
we SPECIFY,
including its
Subfolder Files
College of Scripting Music & Science
Christopher Topalian
Show File Path Names of Files in Any Folder
that we specify
import os

path = "C:/Users/energy/Desktop/ourApp"
We specify the exact location

COLLEGEOFSCRIPTING.WEEBLY.COM
theFiles = [ ] of the folder we want to use
for folder, subfolder, ourFiles in os.walk(path):
for file in ourFiles:
theFiles.append(os.path.join(folder,file))
for theName in theFiles:
print(theName)
input('Press Enter to Exit')

Shows us the full path names of all files in the


folder we specified, and its subfolder files too.
On my computer, I'm using the username
energy. But, in your case, you
write the name of your username instead.
College of Scripting Music & Science
Christopher Topalian

Comments

COLLEGEOFSCRIPTING.WEEBLY.COM
Single Line
Multi Line

College of Scripting Music & Science


Christopher Topalian
COMMENT CODE OUT - Single Line
ourText = 'Hi Everyone'
print(ourText)
# print('Howdy')

COLLEGEOFSCRIPTING.WEEBLY.COM
Type the Pound We place # before any line of
Symbol code to comment that line out.
# The pound symbol is also
# is also known known as the number symbol.
as the Number
Symbol The # symbol is used to
comment ONLY ONE LINE OF
CODE AT A TIME!
# is used for
Single Line The Next page teaches you
Commenting Multi Line Commenting.

College of Scripting Music & Science


Christopher Topalian
COMMENT CODE OUT - Multi Line
'''ourText = 'Hi Everyone'
print(ourText)'''
print('Howdy')

COLLEGEOFSCRIPTING.WEEBLY.COM
Type the Single We place ''' before the first line
Quote Symbol of code to we want to comment
3 Times out, and then place ''' at the end

'''
' is also known
The Single Quote is also known
as the Apostrophe symbol.
as the 3 Single Quotes ''' are used to
Apostrophe comment MULTIPLE LINES
Symbol OF CODE AT A TIME.
3 Single Quotes ''' Next, we learn how to use
are used for Multi comments to document our
Line Commenting code with detailed information.
College of Scripting Music & Science
Christopher Topalian
COMMENT INFO - Single Line
ourText = 'Hi Everyone'
print(ourText) #shows Hi Everyone
print('Howdy') #shows Howdy

COLLEGEOFSCRIPTING.WEEBLY.COM
Type the Pound This time, instead of using
Symbol the # Comment symbol
# to comment code out,
we instead use it to
COMMENT about the code!
# is also known
as the Number Adding Comment information
Symbol to our Code is very useful for
small and large programs.
# is used for It is very good to add many
Single Line comments to our code as we
Commenting are making our applications.
College of Scripting Music & Science
Christopher Topalian
COMMENT INFO – Multi Line
ourText = 'Hi Everyone'
print(ourText)
print('Howdy')
''' We assign a value to ourText

COLLEGEOFSCRIPTING.WEEBLY.COM
we print ourText and Howdy.'''
Type the Single Instead of using the
Quote Symbol 3 Single Quotes ''' to
3 Times comment code out,

''' we now use it to make


multi line COMMENTS
about the code!
' is also known
as the Adding Multi Line Comment
Apostrophe information to our Code is
Symbol very useful in of all our scripts.
We document our code with
3 Single Quotes ''' comments as we are making
are used for Multi our applications.
Line Commenting
College of Scripting Music & Science
Christopher Topalian
Long Lines to Multi Lines is Allowed
import ctypes
ourTitle = 'Instructions' Backslash

COLLEGEOFSCRIPTING.WEEBLY.COM
ourText = 'When coding in Python. \
We can make long lines \
of text. We use the \
backslash to allow the \
multi line style.'
ctypes.windll.user32.MessageBoxW(0,
ourText, ourTitle, 0)
We can use the BACK SLASH \ to tell the Python
editor to allow long lines of code to be placed onto
multiple lines instead the one long line. This is very
useful for increased readability, for the person scripting.
College of Scripting Music & Science
Christopher Topalian
Long Lines to Multi Lines is Allowed
import ctypes
ourTitle = 'Instructions'
ourText = ('When coding in Python. '

COLLEGEOFSCRIPTING.WEEBLY.COM
'We can make long lines '
'of text. We use the '
'backslash to allow the '
'multi line style.') Parenthesis
ctypes.windll.user32.MessageBoxW(0,
ourText, ourTitle, 0)
Another way that we can achieve this increased
readability is with PARENTHESIS and
QUOTATION MARKS, to tell the Python editor to
allow long lines to be allowed as a multiple line
section, to make it easier for the person scripting.
College of Scripting Music & Science
Christopher Topalian

COLLEGEOFSCRIPTING.WEEBLY.COM
VARIABLES
&
FUNCTIONS

College of Scripting Music & Science


Christopher Topalian
Global, Local Variables, Function, return
import ctypes
Global Variable
ourTitle = "Greeting App"
custom function

COLLEGEOFSCRIPTING.WEEBLY.COM
def ourFunction():
ourText = "Howdy" Local Variable
return ourText
return the Variable
ctypes.windll.user32.MessageBoxW(0,
ourFunction(), ourTitle, 0)

ourTitle is a global variable, that is a string.


ourText is a local variable, that is a string.
ourTitle can be used in other functions,
because it is global.
ourText can only be used in ourFunction(),
because it is local to ourFunction().
College of Scripting Music & Science
Christopher Topalian
TABBING CODE for Our Functions
import ctypes Empty Notice, we use
Global the TAB button
ourTitle = ' ' String on our Keyboard!
ourText = ' ' Variables
TAB

COLLEGEOFSCRIPTING.WEEBLY.COM
def ourTitleFunction():
ourTitle = "Greeting App" TABS are
return ourTitle important in
Python
def ourTextFunction(): Language!
ourText = "Hi Everyone"
return ourText
ctypes.windll.user32.MessageBoxW(0,
ourTextFunction(), ourTitleFunction(), 0)

We make our custom function by writing


def ourTitleFunction(): and on the next line,
we press the TAB button on our keyboards,
to add a TAB space.
College of Scripting Music & Science
Christopher Topalian

Tab a Section Easily


We Select any Section of Code
that we want to Tab to the Left.

Control + [

COLLEGEOFSCRIPTING.WEEBLY.COM
Tabs our code to the LEFT

We Select any Section of Code


that we want to Tab to the Right.

Control + ]
Tabs our code to the RIGHT
College of Scripting Music & Science
Christopher Topalian

COLLEGEOFSCRIPTING.WEEBLY.COM
INTERNET

College of Scripting Music & Science


Christopher Topalian
Open Web Browser, Go to URL
import webbrowser
theUrl = 'https://google.com'
webbrowser.open(theUrl, new=2)

COLLEGEOFSCRIPTING.WEEBLY.COM
new = 0 new = 1 new = 2
open URL open URL open URL
in same in new in new tab
window window
College of Scripting Music & Science
Christopher Topalian
Read Web Page Data, urllib
import urllib.request
temp = 'https://www.google.com/'
theUrl = urllib.request.urlopen(temp)

COLLEGEOFSCRIPTING.WEEBLY.COM
print(theUrl.read())
input('Press Enter to Close App')

Double
Click to
Show
the
Data
College of Scripting Music & Science
Christopher Topalian
Read Web Page Data, urllib, wrapped
import urllib.request
theUrl = (urllib.request.urlopen(
'https://www.google.com/'))

COLLEGEOFSCRIPTING.WEEBLY.COM
print(theUrl.read())
input('Press Enter to Close App')

This script is very similar to the script


on the previous page,
but, in this version, we have
wrapped the code statement
with parenthesis,
to allow us to put the long line of code
on multiple lines, for easy coding!
College of Scripting Music & Science
Christopher Topalian

COLLEGEOFSCRIPTING.WEEBLY.COM
List of
Dictionaries

College of Scripting Music & Science


Christopher Topalian
List of Dictionaries - Show All
people = [
{
'name' : 'Melissa',
'date' : '2021/04/01',

COLLEGEOFSCRIPTING.WEEBLY.COM
},
{
'name' : 'Tabitha',
'date' : '2021/04/05'
}
]
print(people)
input('Press Enter to Exit')
[{'name': 'Melissa', 'date': '2021/04/01'}, {'name':
'Tabitha', 'date': '2021/04/05'}]
College of Scripting Music & Science
Christopher Topalian
List of Dictionaries - Show All
people = [
{
'name' : 'Melissa',

COLLEGEOFSCRIPTING.WEEBLY.COM
'age' : 47,
},
{
'name' : 'Tabitha',
'age' : 52
}
]
print(people)
input('Press Enter to Exit')
[{'name': 'Melissa', 'age': 47}, {'name': 'Tabitha',
'age': 52}]
College of Scripting Music & Science
Christopher Topalian
List of Dictionaries - Show All
people = [
{
'name' : 'Melissa',
'date' : '2021/04/01',

COLLEGEOFSCRIPTING.WEEBLY.COM
},
{
'name' : 'Tabitha',
'date' : '2021/04/05'
}
]
x=0
while x < len(people):
print(people[x])
x += 1
input('Press Enter to Exit')
{'name': 'Melissa', 'date': '2021/04/01'}
{'name': 'Tabitha', 'date': '2021/04/05'}
College of Scripting Music & Science
Christopher Topalian
List of Dictionaries - Show All
people = [
{
'name' : 'Melissa',
'date' : '2021/04/01',

COLLEGEOFSCRIPTING.WEEBLY.COM
},
{
'name' : 'Tabitha',
'date' : '2021/04/05'
}
]
for z in range(len(people)):
print(people[z])
input('Press Enter to Exit')
{'name': 'Melissa', 'date': '2021/04/01'}
{'name': 'Tabitha', 'date': '2021/04/05'}
College of Scripting Music & Science
Christopher Topalian

List of

COLLEGEOFSCRIPTING.WEEBLY.COM
Dictionaries
SHOW KEY

College of Scripting Music & Science


Christopher Topalian
List of Dictionaries - Show All Names
people = [ Melissa
{ Tabitha
'name' : 'Melissa',
'date' : '2021/04/01',

COLLEGEOFSCRIPTING.WEEBLY.COM
},
{
'name' : 'Tabitha',
'date' : '2021/04/05'
}
]
x=0
while x < len(people):
print(people[x]['name'])
x += 1
input('Press Enter to Exit')
College of Scripting Music & Science
Christopher Topalian
List of Dictionaries - Show All Dates
people = [ 2021/04/01
{ 2021/04/05
'name' : 'Melissa',
'date' : '2021/04/01',

COLLEGEOFSCRIPTING.WEEBLY.COM
},
{
'name' : 'Tabitha',
'date' : '2021/04/05'
}
]
x=0
while x < len(people):
print(people[x]['date'])
x += 1
input('Press Enter to Exit')
College of Scripting Music & Science
Christopher Topalian
List of Dictionaries - Show First Letter
people = [ M
{ T
'name' : 'Melissa',
'date' : '2021/04/01',

COLLEGEOFSCRIPTING.WEEBLY.COM
},
{
'name' : 'Tabitha',
'date' : '2021/04/05'
}
]
x=0
while x < len(people):
print(people[x]['name'][0])
x += 1
input('Press Enter to Exit')
College of Scripting Music & Science
Christopher Topalian
List of Dictionaries - Show First Letters
people = [ Mel
{
'name' : 'Melissa',
Tab
'date' : '2021/04/01',

COLLEGEOFSCRIPTING.WEEBLY.COM
},
{
'name' : 'Tabitha',
'date' : '2021/04/05'
}
]
x=0
while x < len(people):
print(people[x]['name'][0] +
people[x]['name'][1] +
people[x]['name'][2])
x += 1
input('Press Enter to Exit')
College of Scripting Music & Science
Christopher Topalian
List of Dictionaries - Show All Names
people = [ Melissa
{ Tabitha
'name' : 'Melissa',

COLLEGEOFSCRIPTING.WEEBLY.COM
'date' : '2021/04/01',
},
{
'name' : 'Tabitha',
'date' : '2021/04/05'
}
]
for z in range(len(people)):
print(people[z]['name'])
input('Press Enter to Exit')
College of Scripting Music & Science
Christopher Topalian
List of Dictionaries - Show All Names
people = [ Melissa
{ Tabitha
'name' : 'Melissa',

COLLEGEOFSCRIPTING.WEEBLY.COM
'date' : '2021/04/01',
},
{
'name' : 'Tabitha',
'date' : '2021/04/05'
}
]
for z in range(len(people)):
print(people[z]['name'] + '\n')
input('Press Enter to Exit')
College of Scripting Music & Science
Christopher Topalian
List of Dictionaries – Show All Dates
people = [ 2021/04/01
{ 2021/04/05
'name' : 'Melissa',

COLLEGEOFSCRIPTING.WEEBLY.COM
'date' : '2021/04/01',
},
{
'name' : 'Tabitha',
'date' : '2021/04/05'
}
]
for z in range(len(people)):
print(people[z]['date'] + '\n')
input('Press Enter to Exit')
College of Scripting Music & Science
Christopher Topalian
List of Dictionaries - Show Name, Date
people = [ Melissa
{ 2021/04/01
Tabitha
'name' : 'Melissa', 2021/04/05
'date' : '2021/04/01',

COLLEGEOFSCRIPTING.WEEBLY.COM
},
{
'name' : 'Tabitha',
'date' : '2021/04/05'
}
]
for z in range(len(people)):
print(people[z]['name'] + '\n' +
people[z]['date'] + '\n\n')
input('Press Enter to Exit')
College of Scripting Music & Science
Christopher Topalian
List of Dictionaries - Show All
import ctypes The Characters X

characters = [ Superman
{ Batman
'name': 'Superman', OK

COLLEGEOFSCRIPTING.WEEBLY.COM
'location': 'Metropolis'
},
{
'name': 'Batman',
'location': 'Gotham'
}
]
answer = " "
for z in range(len(characters)):
answer += characters[z]['name'] + '\n'
print(z)
ctypes.windll.user32.MessageBoxW(0,
answer, "The Characters", 0)
College of Scripting Music & Science
Christopher Topalian
List of Dictionaries in Window, Labels
from tkinter import *
characters = [
{
'name': 'Superman', Superman
'location': 'Metropolis'
}, Batman

COLLEGEOFSCRIPTING.WEEBLY.COM
{
'name': 'Batman',
'location': 'Gotham'
}
]
ourWindow = Tk()
ourWindow.geometry('215x175+300+150')
ourWindow.title('Our App')
x = 75
y=1
answer = ''
for z in range(len(characters)):
answer = characters[z]['name']
y += 40
Label(ourWindow,
text = answer, fg = 'aqua', bg = 'black').place(x = x, y = y)
ourWindow.mainloop()
College of Scripting Music & Science
Christopher Topalian
List of Dictionaries in Window, 1 label
from tkinter import *
characters = [
{ Superman
'name': 'Superman', Batman
'location': 'Metropolis'
},

COLLEGEOFSCRIPTING.WEEBLY.COM
{
'name': 'Batman',
'location': 'Gotham'
}
]
ourWindow = Tk()
ourWindow.geometry('215x175+300+150')
ourWindow.title('Our App')
x = 75
y=0
answer = " "
for z in range(len(characters)):
answer += characters[z]['name'] + '\n'
ourFirstLabel = Label(ourWindow,
text = answer, fg = 'aqua', bg = 'black').place(x = x, y = y)
ourWindow.mainloop()
College of Scripting Music & Science
Christopher Topalian

List of

COLLEGEOFSCRIPTING.WEEBLY.COM
Dictionaries
FILTER BY
NAME
College of Scripting Music & Science
Christopher Topalian
List of Dictionaries – Show Name
people = [ Hi Melissa
{
'name' : 'Melissa',
'date' : '2021/04/01',

COLLEGEOFSCRIPTING.WEEBLY.COM
},
{
'name' : 'Tabitha',
'date' : '2021/04/05'
}
]
x=0
while x < len(people):
if(people[x]['name']=='Melissa'):
print('Hi Melissa')
x += 1
input('Press Enter to Exit')
College of Scripting Music & Science
Christopher Topalian
List of Dictionaries – Show Name
people = [ Hi Melissa
{
'name' : 'Melissa',
'date' : '2021/04/01',

COLLEGEOFSCRIPTING.WEEBLY.COM
},
{
'name' : 'Tabitha',
'date' : '2021/04/05'
}
]
for z in range(len(people)):
if(people[z]['name']=='Melissa'):
print('Hi Melissa')
input('Press Enter to Exit')

College of Scripting Music & Science


Christopher Topalian
List of Dictionaries - Show Name
import ctypes The Characters X
characters = [
Superman
{
'name': 'Superman', OK
'location': 'Metropolis'

COLLEGEOFSCRIPTING.WEEBLY.COM
},
{
'name': 'Batman',
'location': 'Gotham'
}
]
answer = " "
for z in range(len(characters)):
if(characters[z]['name']=='Superman'):
answer += characters[z]['name'] + '\n'
print(z)
ctypes.windll.user32.MessageBoxW(0,
answer, "The Characters", 0)
College of Scripting Music & Science
Christopher Topalian
List of Dictionaries in Window – Show Name
from tkinter import *
characters = [
{
'name': 'Superman',
'location': 'Metropolis'
}, Superman

COLLEGEOFSCRIPTING.WEEBLY.COM
{
'name': 'Batman',
'location': 'Gotham'
}
]
ourWindow = Tk()
ourWindow.geometry('215x175+300+150')
ourWindow.title('Our App')
x = 75
y=1
answer = ''
for z in range(len(characters)):
if(characters[z]['name']=='Superman'):
answer = characters[z]['name']
y += 40
Label(ourWindow,
text = answer, fg = 'aqua', bg = 'black').place(x = x, y = y)
ourWindow.mainloop()
College of Scripting Music & Science
Christopher Topalian

List of

COLLEGEOFSCRIPTING.WEEBLY.COM
Dictionaries
FILTER BY
DATE
College of Scripting Music & Science
Christopher Topalian
List of Dictionaries – if Date Greater Than
people = [
{
'name' : 'Melissa',
'date' : '2021/04/01',

COLLEGEOFSCRIPTING.WEEBLY.COM
},
{
'name' : 'Tabitha',
'date' : '2021/04/05'
}
]
x=0
while x < len(people):
if(people[x]['date'] > '2021/04/02'):
print(people[x])
x += 1
input('Press Enter to Exit')
{'name': 'Tabitha', 'date': '2021/04/05'}
College of Scripting Music & Science
Christopher Topalian
List of Dictionaries – if Date Greater Than

people = [
{
'name' : 'Melissa',
'date' : '2021/04/01',

COLLEGEOFSCRIPTING.WEEBLY.COM
},
{
'name' : 'Tabitha',
'date' : '2021/04/05'
}
]

for z in range(len(people)):
if(people[z]['date'] > '2021/04/02'):
print(people[z])
input('Press Enter to Exit')

{'name': 'Tabitha', 'date': '2021/04/05'}


College of Scripting Music & Science
Christopher Topalian
List of Dictionaries – if Date Greater Than
people = [ Tabitha
{
'name' : 'Melissa',
'date' : '2021/04/01',

COLLEGEOFSCRIPTING.WEEBLY.COM
},
{
'name' : 'Tabitha',
'date' : '2021/04/05'
}
]
x=0
while x < len(people):
if(people[x]['date'] > '2021/04/02'):
print(people[x]['name'])
x += 1
input('Press Enter to Exit')
College of Scripting Music & Science
Christopher Topalian
List of Dictionaries – if Date Greater Than

people = [ Tabitha
{
'name' : 'Melissa',

COLLEGEOFSCRIPTING.WEEBLY.COM
'date' : '2021/04/01',
},
{
'name' : 'Tabitha',
'date' : '2021/04/05'
}
]
for z in range(len(people)):
if(people[z]['date'] > '2021/04/02'):
print(people[z]['name'])
input('Press Enter to Exit')
College of Scripting Music & Science
Christopher Topalian
List of Dictionaries - if Date Less Than
people = [ Filter by
{ Year,
'name' : 'Melissa', Month, Day
'date' : '2021/04/01',

COLLEGEOFSCRIPTING.WEEBLY.COM
},
{ Melissa
'name' : 'Tabitha', 2021/04/01
'date' : '2021/04/05'
}
]
x=0
while x < len(people):
if(people[x]['date'] < '2021/04/02'):
print(people[x]['name'] + '\n' +
people[x]['date'])
x += 1
input('Press Enter to Exit')
College of Scripting Music & Science
Christopher Topalian
List of Dictionaries - if Date Less Than
people = [ Filter by
{ Year,
'name' : 'Melissa', Month, Day
'date' : '2021/04/01',

COLLEGEOFSCRIPTING.WEEBLY.COM
},
{ Melissa
'name' : 'Tabitha', 2021/04/01
'date' : '2021/04/05'
}
]
for z in range(len(people)):
if(people[z]['date'] < '2021/04/02'):
print(people[z]['name'] + '\n' +
people[z]['date'])
input('Press Enter to Exit')
College of Scripting Music & Science
Christopher Topalian
List of Dictionaries - if Date Greater Than
people = [ FILTER BY
{ YEAR
'name' : 'Melissa',
'date' : '2021/04/01',

COLLEGEOFSCRIPTING.WEEBLY.COM
},
{
'name' : 'Tabitha',
'date' : '2021/04/05'
}
]
x=0
while x < len(people):
if(people[x]['date'] > '2021'):
print(people[x])
x += 1
input('Press Enter to Exit')
{'name': 'Melissa', 'date': '2021/04/01'}
{'name': 'Tabitha', 'date': '2021/04/05'}
College of Scripting Music & Science
Christopher Topalian
List of Dictionaries - if Date Greater Than
people = [ FILTER BY
{ YEAR AND
'name' : 'Melissa', MONTH
'date' : '2021/04/01',

COLLEGEOFSCRIPTING.WEEBLY.COM
},
{
'name' : 'Tabitha',
'date' : '2021/04/05'
}
]
x=0
while x < len(people):
if(people[x]['date'] > '2021/04'):
print(people[x])
x += 1
input('Press Enter to Exit')
{'name': 'Melissa', 'date': '2021/04/01'}
{'name': 'Tabitha', 'date': '2021/04/05'}
College of Scripting Music & Science
Christopher Topalian
List of Dictionaries – if Date Equal To
people = [ FILTER BY
{ EXACT
'name' : 'Melissa', DATE
'date' : '2021/04/01',

COLLEGEOFSCRIPTING.WEEBLY.COM
},
{
'name' : 'Tabitha',
'date' : '2021/04/05'
}
]
x=0
while x < len(people):
if(people[x]['date'] == '2021/04/05'):
print(people[x])
x += 1
input('Press Enter to Exit')

{'name': 'Tabitha', 'date': '2021/04/05'}


College of Scripting Music & Science
Christopher Topalian
List of Dictionaries – if Date Greater Than
people = [ FILTER BY
{ EXACT
'name' : 'Melissa', DATE and
'date' : '2021/04/01 10:00AM', TIME

COLLEGEOFSCRIPTING.WEEBLY.COM
},
{
'name' : 'Tabitha',
'date' : '2021/04/01 12:00AM'
}
]
x=0
while x < len(people):
if(people[x]['date'] > '2021/04/01 08:00AM'):
print(people[x])
x += 1
input('Press Enter to Exit')
{'name': 'Melissa', 'date': '2021/04/01 10:00AM'}
{'name': 'Tabitha', 'date': '2021/04/01 12:00AM'}
College of Scripting Music & Science
Christopher Topalian

List of
Dictionaries

COLLEGEOFSCRIPTING.WEEBLY.COM
FILTER BY
DATE
using
and
College of Scripting Music & Science
List of Dictionaries Christopher Topalian
if Date is Greater Than and Less Than
people = [ Melissa
{
'name' : 'Melissa',
'date' : '2021/03/31',

COLLEGEOFSCRIPTING.WEEBLY.COM
},
{
'name' : 'Tabitha',
'date' : '2021/04/05'
}
]
x=0
while x < len(people):
if(people[x]['date'] > '2021/03/30' and
people[x]['date'] < '2021/04/04'):
print(people[x]['name'])
x += 1
input('Press Enter to Exit')
College of Scripting Music & Science
List of Dictionaries Christopher Topalian
if Date is Greater Than and Less Than
people = [ Melissa
{
'name' : 'Melissa',
'date' : '2021/03/31',

COLLEGEOFSCRIPTING.WEEBLY.COM
},
{
'name' : 'Tabitha',
'date' : '2021/04/05'
}
]
for z in range(len(people)):
if(people[z]['date'] > '2021/03/30' and
people[z]['date'] < '2021/04/04'):
print(people[z]['name'])
input('Press Enter to Exit')

College of Scripting Music & Science


List of Dictionaries – if nameChristopher
and loc Topalian

import ctypes The Characters X


characters = [
Superman
{
'name': 'Superman', OK
'location': 'Metropolis'

COLLEGEOFSCRIPTING.WEEBLY.COM
},
{
'name': 'Batman',
'location': 'Gotham'
}
]
answer = " "
for z in range(len(characters)):
if(characters[z]['name']=='Superman'
and characters[z]['location']=='Metropolis'):
answer += characters[z]['name'] + '\n'
ctypes.windll.user32.MessageBoxW(0,
answer, "The Characters", 0)
College of Scripting Music & Science
Christopher Topalian
List of Dictionaries in Window - if name and loc
from tkinter import *
characters = [
{
'name': 'Superman',
'location': 'Metropolis'
}, Superman

COLLEGEOFSCRIPTING.WEEBLY.COM
{
'name': 'Batman',
'location': 'Gotham'
}
]
ourWindow = Tk()
ourWindow.geometry('215x175+300+150')
ourWindow.title('Our App')
x = 75
y=1
answer = ''
for z in range(len(characters)):
if(characters[z]['name']=='Superman'
and characters[z]['location']=='Metropolis'):
answer = characters[z]['name']
y += 40
Label(ourWindow,
text = answer, fg = 'aqua', bg = 'black').place(x = x, y = y)
ourWindow.mainloop() College of Scripting Music & Science
Christopher Topalian

List of
Dictionaries

COLLEGEOFSCRIPTING.WEEBLY.COM
FILTER BY
DATE
using
or
College of Scripting Music & Science
List of Dictionaries Christopher Topalian
if Date is Less Than or Greater Than
people = [ Melissa
{
'name' : 'Melissa',
Tabitha
'date' : '2021/03/31',

COLLEGEOFSCRIPTING.WEEBLY.COM
},
{
'name' : 'Tabitha',
'date' : '2021/04/05'
}
]
x=0
while x < len(people):
if(people[x]['date'] < '2021/04/04' or
people[x]['date'] > '2021/04/01'):
print(people[x]['name'])
x += 1
input('Press Enter to Exit')
College of Scripting Music & Science
List of Dictionaries Christopher Topalian
if Date is Less Than or Greater Than
people = [ Melissa
{ Tabitha
'name' : 'Melissa',
'date' : '2021/03/31',

COLLEGEOFSCRIPTING.WEEBLY.COM
},
{
'name' : 'Tabitha',
'date' : '2021/04/05'
}
]
for z in range(len(people)):
if(people[z]['date'] < '2021/04/04' or
people[z]['date'] > '2021/04/01'):
print(people[z]['name'])
input('Press Enter to Exit')
College of Scripting Music & Science
List of Dictionaries Christopher Topalian
if Date is Less Than or Greater Than
import ctypes The People X
people = [ Melissa
{ Tabitha
'name' : 'Melissa',

COLLEGEOFSCRIPTING.WEEBLY.COM
OK
'date' : '2021/03/31',
},
{
'name' : 'Tabitha',
'date' : '2021/04/05'
}
]
answer = " "
for z in range(len(people)):
if(people[z]['date'] < '2021/04/04'
or people[z]['date'] > '2021/04/01'):
answer += people[z]['name'] + '\n'
ctypes.windll.user32.MessageBoxW(0,
answer, "The People", 0)
College of Scripting Music & Science
Christopher Topalian
List of Dictionaries in Window – Show Name
from tkinter import *
people = [
{
'name' : 'Melissa', Melissa
'date' : '2021/03/31',
}, Tabitha

COLLEGEOFSCRIPTING.WEEBLY.COM
{
'name' : 'Tabitha',
'date' : '2021/04/05'
}
]
ourWindow = Tk()
ourWindow.geometry('215x175+300+150')
ourWindow.title('Our App')
x = 75
y=1
answer = " "
for z in range(len(people)):
if(people[z]['date'] < '2021/04/04'
or people[z]['date'] > '2021/04/01'):
answer = people[z]['name']
y += 40
Label(ourWindow,
text = answer, fg = 'aqua', bg = 'black').place(x = x, y = y)
ourWindow.mainloop()
College of Scripting Music & Science
Christopher Topalian

List of

COLLEGEOFSCRIPTING.WEEBLY.COM
Dictionaries
APPEND

College of Scripting Music & Science


Christopher Topalian
List of Dictionaries - APPEND
people = [ Melissa
{ Tabitha
'name' : 'Melissa', John
'date' : '2021/03/31',

COLLEGEOFSCRIPTING.WEEBLY.COM
},
{
'name' : 'Tabitha',
'date' : '2021/04/05'
}
]
people.append({'name':'John', 'date':'2022/03/23'})
x=0
while x < len(people):
if(people[x]['date'] > '2021/01/04' and
people[x]['date'] < '2023/02/01'):
print(people[x]['name'])
x += 1
input('Press Enter to Exit')
College of Scripting Music & Science
Christopher Topalian
List of Dictionaries - APPEND
people = [ Melissa
{ Tabitha
'name' : 'Melissa', John
'date' : '2021/03/31',

COLLEGEOFSCRIPTING.WEEBLY.COM
},
{
'name' : 'Tabitha',
'date' : '2021/04/05'
}
]
people.append({'name':'John', 'date':'2022/03/23'})

for z in range(len(people)):
if(people[z]['date'] > '2021/01/04' and
people[z]['date'] < '2023/02/01'):
print(people[z]['name'])
input('Press Enter to Exit')

College of Scripting Music & Science


Christopher Topalian

List of

COLLEGEOFSCRIPTING.WEEBLY.COM
Dictionaries
DELETE

College of Scripting Music & Science


Christopher Topalian
List of Dictionaries - Delete
people = [ Tabitha
{
'name' : 'Melissa',
'date' : '2021/03/31',

COLLEGEOFSCRIPTING.WEEBLY.COM
},
{
'name' : 'Tabitha',
'date' : '2021/04/05'
}
]
del people['name'=='Melissa']
x=0
while x < len(people):
if(people[x]['date'] > '2021/01/04' and
people[x]['date'] < '2023/02/01'):
print(people[x]['name'])
x += 1
input('Press Enter to Exit')
College of Scripting Music & Science
Christopher Topalian
List of Dictionaries - Delete
people = [ Tabitha
{
'name' : 'Melissa',
'date' : '2021/03/31',

COLLEGEOFSCRIPTING.WEEBLY.COM
},
{
'name' : 'Tabitha',
'date' : '2021/04/05'
}
]
del people['name'=='Melissa']

for z in range(len(people)):
if(people[z]['date'] > '2021/01/04' and
people[z]['date'] < '2023/02/01'):
print(people[z]['name'])
input('Press Enter to Exit')

College of Scripting Music & Science


Christopher Topalian

List of

COLLEGEOFSCRIPTING.WEEBLY.COM
Dictionaries
DELETE
Last Item

College of Scripting Music & Science


Christopher Topalian
List of Dictionaries - pop
people = [
{ Melissa
'name' : 'Melissa',
'date' : '2021/03/31',

COLLEGEOFSCRIPTING.WEEBLY.COM
},
{
'name' : 'Tabitha',
'date' : '2021/04/05'
}
]
people.pop()
x=0
while x < len(people):
if(people[x]['date'] > '2021/01/04' and
people[x]['date'] < '2023/02/01'):
print(people[x]['name'])
x += 1
input('Press Enter to Exit')
College of Scripting Music & Science
Christopher Topalian
List of Dictionaries - pop
people = [ Melissa
{
'name' : 'Melissa',
'date' : '2021/03/31',

COLLEGEOFSCRIPTING.WEEBLY.COM
},
{
'name' : 'Tabitha',
'date' : '2021/04/05'
}
]
people.pop()

for z in range(len(people)):
if(people[z]['date'] > '2021/01/04' and
people[z]['date'] < '2023/02/01'):
print(people[z]['name'])
input('Press Enter to Exit')
College of Scripting Music & Science
Christopher Topalian

List of

COLLEGEOFSCRIPTING.WEEBLY.COM
Dictionaries
EDIT by
Index
College of Scripting Music & Science
Christopher Topalian
List of Dictionaries – Edit by Index
people = [ John
{ Tabitha
'name' : 'Melissa',
'date' : '2021/03/31',

COLLEGEOFSCRIPTING.WEEBLY.COM
},
{
'name' : 'Tabitha',
'date' : '2021/04/05'
}
]
people[0]=({'name':'John', 'date':'2022/03/23'})
x=0
while x < len(people):
if(people[x]['date'] > '2021/01/04' and
people[x]['date'] < '2023/02/01'):
print(people[x]['name'])
x += 1
input('Press Enter to Exit')
College of Scripting Music & Science
Christopher Topalian
List of Dictionaries – Edit by Index
people = [ John
{ Tabitha
'name' : 'Melissa',
'date' : '2021/03/31',

COLLEGEOFSCRIPTING.WEEBLY.COM
},
{
'name' : 'Tabitha',
'date' : '2021/04/05'
}
]
people[0]=({'name':'John', 'date':'2022/03/23'})

for z in range(len(people)):
if(people[z]['date'] > '2021/01/04' and
people[z]['date'] < '2023/02/01'):
print(people[z]['name'])
input('Press Enter to Exit')

College of Scripting Music & Science


Christopher Topalian

List of

COLLEGEOFSCRIPTING.WEEBLY.COM
Dictionaries
EDIT by Key

College of Scripting Music & Science


Christopher Topalian
List of Dictionaries – Edit by Key
people = [ John
{
Tabitha
'name' : 'Melissa',
'date' : '2021/03/31',
},

COLLEGEOFSCRIPTING.WEEBLY.COM
{
'name' : 'Tabitha',
'date' : '2021/04/05'
}
]
people['name'=='Melissa']=({'name':'John',
'date':'2022/03/23'})
x=0
while x < len(people):
if(people[x]['date'] > '2021/01/04' and
people[x]['date'] < '2023/02/01'):
print(people[x]['name'])
x += 1
input('Press Enter to Exit')
College of Scripting Music & Science
Christopher Topalian
List of Dictionaries – Edit by Key
people = [ John
{ Tabitha
'name' : 'Melissa',
'date' : '2021/03/31',

COLLEGEOFSCRIPTING.WEEBLY.COM
},
{
'name' : 'Tabitha',
'date' : '2021/04/05'
}
]
people['name'=='Melissa']=({'name':'John',
'date':'2022/03/23'})

for z in range(len(people)):
if(people[z]['date'] > '2021/01/04' and
people[z]['date'] < '2023/02/01'):
print(people[z]['name'])
input('Press Enter to Exit')
College of Scripting Music & Science
Christopher Topalian

List of

COLLEGEOFSCRIPTING.WEEBLY.COM
Dictionaries
EXTEND

College of Scripting Music & Science


List of Dictionaries – Extend
Christopher Topalian

people = [
{ Melissa
'name' : 'Melissa', Tabitha
'date' : '2021/03/31', James
},
{ Debra
'name' : 'Tabitha',

COLLEGEOFSCRIPTING.WEEBLY.COM
'date' : '2021/04/05'
}
]
characters = [
{
'name' : 'James',
'date' : '2010/08/31',
},
{
'name' : 'Debra',
'date' : '2012/06/02'
}
]
people.extend(characters)
for z in range(len(people)):
if(people[z]['date'] > '2009/01/04' and
people[z]['date'] < '2023/02/01'):
print(people[z]['name'])
input('Press Enter to Exit')College of Scripting Music & Science
Christopher Topalian

EXTERNAL
FILE
for

COLLEGEOFSCRIPTING.WEEBLY.COM
EASIER
READABILITY
aka
Making a
Module
College of Scripting Music & Science
Christopher Topalian
How to Make a MODULE
Make a New Make a New
Script named Script named
ourScript.py ourData.py

COLLEGEOFSCRIPTING.WEEBLY.COM
ourScript.py will use the data that is
located in the file named ourData.py

We place BOTH
ourScript.py
and
ourData.py
in the
SAME FOLDER
College of Scripting Music & Science
Christopher Topalian
Import our Module using import
Our External file is called a MODULE.
We saved our module as ourData.py

import ourData

COLLEGEOFSCRIPTING.WEEBLY.COM
print(ourData.ourText)
input('Press Enter to Exit')

We import ourData.py file by stating


import ourData
This method keeps the namespace of our code clean.
We include the module name to use the data.

print(ourData.ourText)
College of Scripting Music & Science
Christopher Topalian
First Way of Importing ourData.py

COLLEGEOFSCRIPTING.WEEBLY.COM
import ourData ourText = 'Howdy'

print(ourData.ourText) ourData.py has


only one line of
input('Press Enter to Exit') code, which is the
ourText variable
ourScript.py imports assigned with the
the module named value of 'Howdy'
ourData.py and prints This is called:
the ourText variable Creating a Module!
to the console.
College of Scripting Music & Science
Christopher Topalian

COLLEGEOFSCRIPTING.WEEBLY.COM
Double Click ourScript.py
and notice how it USES the Data
from ourData.py

Remember
ourScript.py
and
ourData.py
are in the
SAME FOLDER!
College of Scripting Music & Science
Christopher Topalian
Second Way of Importing ourData.py
Our External file, is called a MODULE.
We saved our module as ourData.py
from ourData import*
makes coding easy, since we can use the data

COLLEGEOFSCRIPTING.WEEBLY.COM
without needing to include its reference name.
Allows us to use the module data
without having to include the name of the module,
but, it is also less descriptive, of functions source!

print(ourText)
from ourData import*
print(ourText)
input('Press Enter to Exit')
College of Scripting Music & Science
Christopher Topalian
Second Way of Importing ourData.py

COLLEGEOFSCRIPTING.WEEBLY.COM
from ourData import* ourText = 'Howdy'

print(ourText) ourData.py has


only one line of
input('Press Enter to Exit') code, which is the
ourText variable
ourScript.py imports assigned with the
the module named value of 'Howdy'
ourData.py and prints This is called:
the ourText variable Creating a Module!
to the console.
College of Scripting Music & Science
Christopher Topalian

EXTERNAL

COLLEGEOFSCRIPTING.WEEBLY.COM
FILE
Example 2

College of Scripting Music & Science


Christopher Topalian
Our External Data File saved as ourData.py
speakersUSA = [
{ We save this
'name': 'Jane Doe', script as
'title': 'Genetics Lecture', ourData.py
'date': '2022/04/20 07:00 AM'
},

COLLEGEOFSCRIPTING.WEEBLY.COM
{ On the next
'name': 'John Doe', tutorial page,
'title': 'Mechanics Lecture', the script
'date': '2022/04/20 09:00 AM' named
} ourScript.py
] uses the data
speakersEU = [ from this page.
{
'name': 'Rose Doe',
'title': 'Botany Lecture', We place BOTH
'date': '2022/04/20 11:00 AM' ourData.py
}, and
{ ourScript.py
'name': 'Ronald Doe', in the
'title': 'Electronics Lecture', SAME
'date': '2022/04/20 01:00 PM' FOLDER!
}
]
College of Scripting Music & Science
from ourData import*Christopher Topalian
import ctypes Allows us
from ourData import* to use the
data without
speakersUSA.append(speakersEU) including
answer = " " module
name,
for z in speakersUSA:

COLLEGEOFSCRIPTING.WEEBLY.COM
but doesn't
answer += str(z) + '\n\n' state where
ctypes.windll.user32.MessageBoxW(0, the data
came from!
answer, "The Speakers", 0)

We save this This script


USES the DATA
script as from the
ourScript.py previous page!

We have BOTH Double Click


ourScript.py ourScript.py
and and notice
ourData.py how it USES
in the the Data from
SAME FOLDER! ourData.py
College of Scripting Music & Science
Christopher Topalian
import ourData
import ctypes, ourData
ourData.speakersUSA.append(ourData.speakersEU)
answer = " "
Dot is used to
for z in ourData.speakersUSA: access the data

COLLEGEOFSCRIPTING.WEEBLY.COM
answer += str(z) + '\n\n'
Keeps Name
ctypes.windll.user32.MessageBoxW(0, Space Clean!
answer, "The Speakers", 0)

We save this This script


USES the DATA
script as from a
ourScript.py previous page!

We have BOTH Double Click


ourScript.py ourScript.py
and and notice
ourData.py how it USES
in the the Data from
SAME FOLDER! ourData.py
College of Scripting Music & Science
Christopher Topalian
from ourData import* append
import ctypes Append the
from ourData import* list named
speakersEU
speakersUSA.append(speakersEU) to the end of
answer = " " the list
named
for z in speakersUSA:

COLLEGEOFSCRIPTING.WEEBLY.COM
speakersUSA
answer += str(name) + '\n\n'
ctypes.windll.user32.MessageBoxW(0,
answer, "The Speakers", 0)

We save this This script


USES the DATA
script as from a
ourScript.py previous page!

We have BOTH Double Click


ourScript.py ourScript.py
and and notice
ourData.py how it USES
in the the Data from
SAME FOLDER! ourData.py
College of Scripting Music & Science
Christopher Topalian

HOW TO

COLLEGEOFSCRIPTING.WEEBLY.COM
OPEN
COMMAND
PROMPT

College of Scripting Music & Science


Christopher Topalian

Shortcut to Open
Command Prompt
Press Windows Key

COLLEGEOFSCRIPTING.WEEBLY.COM
Type CMD
Press Enter

We install packages using this


Command Prompt.
College of Scripting Music & Science
Christopher Topalian

Shortcut to Open
Command Prompt
Press Windows Key + R

COLLEGEOFSCRIPTING.WEEBLY.COM
Type CMD
Press Enter

We install packages using this


Command Prompt.
College of Scripting Music & Science
Christopher Topalian
Python Package Manager

COLLEGEOFSCRIPTING.WEEBLY.COM
We Type
the word

pip
pip to see
what
commands
it offers

Shows
Often
Used
Commands

College of Scripting Music & Science


Christopher Topalian

Find Out
What Packages
We Have Installed

COLLEGEOFSCRIPTING.WEEBLY.COM
pip list

pip list
College of Scripting Music & Science
Christopher Topalian

These
are

COLLEGEOFSCRIPTING.WEEBLY.COM
packages
that
I have
Installed

College of Scripting Music & Science


Christopher Topalian

How to Install
a Package

COLLEGEOFSCRIPTING.WEEBLY.COM
pip install PySimpleGUI

pip install PySimpleGUI


NAME
OF THE
PACKAGE

College of Scripting Music & Science


Christopher Topalian

pip show PySimpleGUI

COLLEGEOFSCRIPTING.WEEBLY.COM
Show information
about the named
installed package.
College of Scripting Music & Science
Christopher Topalian

How to Uninstall
a Package

COLLEGEOFSCRIPTING.WEEBLY.COM
pip uninstall PySimpleGUI

pip uninstall PySimpleGUI


NAME
OF THE
PACKAGE

College of Scripting Music & Science


Christopher Topalian

Install a

COLLEGEOFSCRIPTING.WEEBLY.COM
Package
Using Pip

College of Scripting Music & Science


Christopher Topalian
Open the Command Prompt
1
Left Click
Windows Icon

COLLEGEOFSCRIPTING.WEEBLY.COM
3 Left Click
Command Prompt

2 Start Typing
CMD

College of Scripting Music & Science


Christopher Topalian
Command Prompt

COLLEGEOFSCRIPTING.WEEBLY.COM
Type the Word
pip

On your Keyboard press


ENTER

The Command Prompt opens.


We type the word pip
and then press ENTER on our keyboard.
If everything goes well, pip (Preferred Installer
Program), will open in your command prompt.
College of Scripting Music & Science
Christopher Topalian
pip

COLLEGEOFSCRIPTING.WEEBLY.COM
pip is the python package installer.

We will use pip to install a package named


pyinstaller

pyinstaller is a package we use to make our .exe


file!
College of Scripting Music & Science
Christopher Topalian
What if pip is NOT working?

COLLEGEOFSCRIPTING.WEEBLY.COM
As you can see,
pip is not working.
When we first installed Python,
the CHECKBOX should have been checked
for Add Python 3.9 to PATH!
Add Python 3.9 to PATH

There are multiple ways to fix this issue.


An easy way is to uninstall Python and reinstall,
this time with the Path checkbox marked.
Or we could change the environment variable.
Once pip is working, move to the next page =>
College of Scripting Music & Science
Christopher Topalian

MAKE A
Single File

COLLEGEOFSCRIPTING.WEEBLY.COM
.EXE FILE
with
PyInstaller
College of Scripting Music & Science
Christopher Topalian
Install PyInstaller

COLLEGEOFSCRIPTING.WEEBLY.COM
Type these words
pip install pyInstaller
Keyboard press
ENTER

In our Command Prompt we type the words


pip install pyinstaller
and then press the enter button on our keyboard.

PyInstaller is an excellent package to make EXE


files from our Python scripts!

College of Scripting Music & Science


Christopher Topalian
PyInstaller Installed Successfully

COLLEGEOFSCRIPTING.WEEBLY.COM
Successfully
installed
pyInstaller
Good Job!!!
PyInstaller is now successfully installed!
Now we can make our .exe file using PyInstaller,
as shown on the next pages.
College of Scripting Music & Science
Christopher Topalian
How to Make a --onefile .exe file
We make a Folder on our
Desktop named ourApp

We place any Python script in ourApp Folder.

COLLEGEOFSCRIPTING.WEEBLY.COM
Left Click
Here

to highlight the path

With the Path highlighted, we Type cmd,


as shown on the next tutorial page.
College of Scripting Music & Science
Christopher Topalian
continued from previous page
Type
cmd

Press

COLLEGEOFSCRIPTING.WEEBLY.COM
Enter
On Keyboard

We type cmd in the path area, and then


we press the ENTER button on our keyboard.
This will open ourApp Folder in the
Command Prompt, with the correct path,
as shown on the next tutorial page.
College of Scripting Music & Science
Christopher Topalian
continued from previous page
As you can see, the
Command Prompt opened.

COLLEGEOFSCRIPTING.WEEBLY.COM
Notice that ourApp folder is
chosen correctly for us.

We have ourApp Folder selected correctly


as the chosen directory. We are READY!
NOTE: We could have alternatively chosen the
directory manually, by typing,
cd Desktop\ourApp, and pressing ENTER.
College of Scripting Music & Science
Christopher Topalian
continued from previous page

COLLEGEOFSCRIPTING.WEEBLY.COM
Type these words
pyinstaller --onefile ourScriptName.py
Keyboard press
ENTER
This turns our python script
into an EXECUTABLE FILE!
Remember, ourScriptName
is the name of YOUR script!
The next pages teach you
how to open your First Application.
Good Job!
College of Scripting Music & Science
Christopher Topalian
continued from previous page

COLLEGEOFSCRIPTING.WEEBLY.COM
SUCCESS!!!
Our .exe file has been created!!!

We have successfully
created our .exe file!
We are Now App makers!
College of Scripting Music & Science
Christopher Topalian

CLEANING
UP!

2 Double Left Click


1 the Folder named

COLLEGEOFSCRIPTING.WEEBLY.COM
dist
Double
Left Click
ourApp
Folder

3 Hold Left Click + DRAG the File Named


ourScriptName.exe to Desktop
College of Scripting Music & Science
Christopher Topalian

OPENING
OUR APP :-)
Double Left Click

COLLEGEOFSCRIPTING.WEEBLY.COM
the File named
ourScriptName.exe

Good Job!!!
Our Python Application Opens!
We have made an .exe file!

College of Scripting Music & Science


Christopher Topalian

Launch Our

COLLEGEOFSCRIPTING.WEEBLY.COM
Apps Without
Showing the
Console
Window

College of Scripting Music & Science


Christopher Topalian
Run Scripts Without Launcher Appearing
If we save our scripts as .py
then the Python Launcher window
appears, when we run our scripts.
But, if we save our scripts as .pyw

COLLEGEOFSCRIPTING.WEEBLY.COM
then the Python Launcher Window
will NOT appear.

Greeting Message X

Hi Everyone

OK

continued on next page =>


College of Scripting Music & Science
Christopher Topalian
continued from previous page
Since we saved our script as
ourFirstScript.pyw
the Python Launcher Window will NOT
appear, when we double click our script!

COLLEGEOFSCRIPTING.WEEBLY.COM
Greeting Message X X
GreetingMessage

Hi
HiEveryone
Everyone
OK
OK

This also works for when we make our


script into an .exe file.
When we make the .exe file, we include
the .pyw at the end of the command.
pyinstaller --onefile ourFirstScript.pyw
College of Scripting Music & Science
Christopher Topalian

DATE

COLLEGEOFSCRIPTING.WEEBLY.COM
&
TIME

College of Scripting Music & Science


Date using Message Box
Christopher Topalian

import ctypes
from datetime import date
ourTitle = 'Current Date'

COLLEGEOFSCRIPTING.WEEBLY.COM
today = date.today()
print("Today's date is ", today)
ctypes.windll.user32.MessageBoxW(0,
str(today), ourTitle, 0)

Current
Greeting Message X
Date

2021-02-15
Hi Everyone
OK
OK

College of Scripting Music & Science


Date in a Window Christopher Topalian
from datetime import date
from tkinter import* height y pos
width x pos
ourWindow = Tk()
ourWindow.geometry('275x50+200+150')

COLLEGEOFSCRIPTING.WEEBLY.COM
ourWindow.title('Date in Window')

today = date.today()

ourLabel1 = Label(ourWindow,
text = today, width = '200', font=("Arial", 25),
fg = 'aqua', bg = 'black').pack()

ourWindow.mainloop()

College of Scripting Music & Science


Date using Message Box
Christopher Topalian

import ctypes Current


GreetingDate X
from datetime import date Message
02/15/2021
Hi
ourTitle = 'Current Date' Everyone
OK OK

COLLEGEOFSCRIPTING.WEEBLY.COM
today = date.today()

formatted = today.strftime("%m/%d/%Y")
print("Today's date is ", today)
ctypes.windll.user32.MessageBoxW(0,
str(formatted), ourTitle, 0)

We could also format it with a DASH divider


formatted = today.strftime("%m-%d-%Y")
02-15-2021
College of Scripting Music & Science
Christopher Topalian
Date in Window, Month, Day, Year
from datetime import date
from tkinter import* height y pos
width x pos
ourWindow = Tk()
ourWindow.geometry('275x50+200+150')

COLLEGEOFSCRIPTING.WEEBLY.COM
ourWindow.title('Date in Window')

today = date.today()
theTime = today.strftime("%m/%d/%Y")
ourLabel1 = Label(ourWindow,
text = theTime, width = '200', font=("Arial", 25),
fg = 'aqua', bg = 'black').pack()

ourWindow.mainloop()

College of Scripting Music & Science


Christopher Topalian
Date in Window, YEAR
from datetime import date
from tkinter import* height y pos
width x pos
ourWindow = Tk()
ourWindow.geometry('275x50+200+150')

COLLEGEOFSCRIPTING.WEEBLY.COM
ourWindow.title('Date in Window')

today = date.today()
theTime = today.strftime("%Y")
ourLabel1 = Label(ourWindow,
text = theTime, width = '200', font=("Arial", 25),
fg = 'aqua', bg = 'black').pack()

ourWindow.mainloop()

College of Scripting Music & Science


Date in Window, Month,Christopher
Day Topalian
from datetime import date
from tkinter import* height y pos
width x pos
ourWindow = Tk()
ourWindow.geometry('275x50+200+150')

COLLEGEOFSCRIPTING.WEEBLY.COM
ourWindow.title('Date in Window')

today = date.today()
theTime = today.strftime("%m-%d")
ourLabel1 = Label(ourWindow,
text = theTime, width = '200', font=("Arial", 25),
fg = 'aqua', bg = 'black').pack()

ourWindow.mainloop()

College of Scripting Music & Science


Christopher Topalian
Date in Window, Abbreviated Month, Day
from datetime import date
from tkinter import* height y pos
width x pos
ourWindow = Tk()
ourWindow.geometry('275x50+200+150')

COLLEGEOFSCRIPTING.WEEBLY.COM
ourWindow.title('Date in Window')

today = date.today()
theTime = today.strftime("%b %d")
ourLabel1 = Label(ourWindow,
text = theTime, width = '200', font=("Arial", 25),
fg = 'aqua', bg = 'black').pack()

ourWindow.mainloop()

College of Scripting Music & Science


Christopher Topalian
Date in a Window, MONTH
from datetime import date
from tkinter import* height y pos
width x pos
ourWindow = Tk()
ourWindow.geometry('275x50+200+150')

COLLEGEOFSCRIPTING.WEEBLY.COM
ourWindow.title('Date in Window')

today = date.today()
theTime = today.strftime("%B")
ourLabel1 = Label(ourWindow,
text = theTime, width = '200', font=("Arial", 25),
fg = 'aqua', bg = 'black').pack()

ourWindow.mainloop()

College of Scripting Music & Science


Time in Window as H, M, S,Christopher
AM/PM Topalian

from datetime import*


from tkinter import* height y pos
width x pos
ourWindow = Tk()
ourWindow.geometry('275x50+200+150')

COLLEGEOFSCRIPTING.WEEBLY.COM
ourWindow.title('Time in Window')

today = datetime.today()
theTime = today.strftime("%H:%M:%S %p")

ourLabel1 = Label(ourWindow,
text = theTime, width = '200', font=("Arial", 25),
fg = 'aqua', bg = 'black').pack()

ourWindow.mainloop()

Hours, Minutes, Seconds AM or PM


College of Scripting Music & Science
Date and Time in a Window
Christopher Topalian

from tkinter import *


from datetime import*
def theDate():
today = date.today()
return today

COLLEGEOFSCRIPTING.WEEBLY.COM
def currentTime():
now = datetime.now()
timeNow = now.strftime("%H:%M:%S")
return timeNow
ourWindow = Tk()
ourWindow.geometry('300x100+300+200')
ourWindow.title('Date App')
theDate = theDate()
theTime = currentTime()
ourLabel1 = Label(ourWindow,
text = theDate, width = '200', font=("Courier", 25),
fg = 'aqua', bg = 'black').pack()
ourLabel2 = Label(ourWindow,
text = theTime, width = '200', font=("Courier", 25),
fg = 'aqua', bg = 'black').pack()
ourWindow.mainloop()
College of Scripting Music & Science
Date and Time in Window with Button
Christopher Topalian

from tkinter import*


from datetime import*
count = 0
def ourCounter():
global count

COLLEGEOFSCRIPTING.WEEBLY.COM
count = datetime.now()
ourLabel1.configure(text = f'{count}')
ourWindow = Tk()
ourWindow.geometry('500x125+200+150')
ourWindow.title("Date and Time")
ourLabel1 = Label(ourWindow, font=("Arial", 25))
ourLabel1.pack()
ourButton = Button(ourWindow, text="Press",
command=ourCounter, font=("Arial", 25))
ourButton.pack()
ourWindow.mainloop()

College of Scripting Music & Science


Christopher Topalian

COLLEGEOFSCRIPTING.WEEBLY.COM
opencv

College of Scripting Music & Science


Christopher Topalian

Computer Vision using OpenCv

COLLEGEOFSCRIPTING.WEEBLY.COM
pip install opencv-python

College of Scripting Music & Science


Christopher Topalian
Show Image
import cv2

img = cv2.imread('ourImage.png')

COLLEGEOFSCRIPTING.WEEBLY.COM
cv2.imshow('Shows Texture', img)

cv2.waitKey(0)

cv2.destroyAllWindows()
We make sure to have our texture
in the same folder as this script
and the texture must be named correctly.
In this case, we are referencing a png file.
Make sure the texture is named ourImage.
College of Scripting Music & Science
Christopher Topalian
Show Image and dimensions
import cv2

img = cv2.imread('ourImage.png')

COLLEGEOFSCRIPTING.WEEBLY.COM
cv2.imshow('Shows Texture', img)

print(img.shape)

cv2.waitKey(0)

cv2.destroyAllWindows()

H W # of channels
(1677, 696, 3)
College of Scripting Music & Science
Christopher Topalian

#Read Image, Show Dimensions


import cv2
img = cv2.imread('ourImage.png')
cv2.imshow('Show Our Texture', img)

COLLEGEOFSCRIPTING.WEEBLY.COM
theHeight = img.shape[0]
theWidth = img.shape[1]
theChannels = img.shape[2]
dimensions = img.shape
print('Height: ', theHeight)
print('Width: ', theWidth)
print('# of Channels: ', theChannels)
print('Dimensions: ', dimensions)
cv2.waitKey(0)
cv2.destroyAllWindows()
College of Scripting Music & Science
Christopher Topalian

#Show dimension,Resize,Show Dimension


import cv2
img = cv2.imread('ourImage.png')
print(' Before:',img.shape)

COLLEGEOFSCRIPTING.WEEBLY.COM
percent = 40
height = int(img.shape[0] * percent / 100)
width = int(img.shape[1] * percent / 100)
dimensions = (width, height)
imgResized = cv2.resize(img, dimensions,
interpolation = cv2.INTER_AREA)
print(' After:',imgResized.shape)
cv2.imshow("Resized Image", imgResized)
cv2.waitKey(0)
cv2.destroyAllWindows()

College of Scripting Music & Science


Christopher Topalian

#Read Image, Make Gray, Save Image

import cv2

COLLEGEOFSCRIPTING.WEEBLY.COM
img = cv2.imread('ourImage.png',
cv2.IMREAD_GRAYSCALE)

saving = cv2.imwrite('gray.png', img)

print("Saving Texture ", saving)

If it is done correctly, Check folder


the output will say: for the saved
Saving Texture True gray texture
College of Scripting Music & Science
Christopher Topalian
#Amount of png Compression
import cv2

img = cv2.imread('ourImage.png',
cv2.IMREAD_UNCHANGED)

COLLEGEOFSCRIPTING.WEEBLY.COM
theNew = cv2.imwrite("new.png", img,
[cv2.IMWRITE_PNG_COMPRESSION, 0])

print("Saving Texture ", theNew)

IMREAD_UNCHANGED
keeps any alpha channel
if not used, alpha channel is removed
IMWRITE_PNG_COMPRESSION, 0
0 for none, 9 for high compression
College of Scripting Music & Science
Christopher Topalian

#Amount of jpg Compression


import cv2

img = cv2.imread('ourImage.png',
cv2.IMREAD_UNCHANGED)

COLLEGEOFSCRIPTING.WEEBLY.COM
theNew = cv2.imwrite("new.jpg", img,
[cv2.IMWRITE_JPEG_QUALITY, 100])

print("Saving Texture ", theNew)

IMREAD_UNCHANGED
keeps any alpha channel
if not used, alpha channel is removed
IMWRITE_JPEG_QUALITY, 0
0 for highest compression, 100 for
lowest compression.
College of Scripting Music & Science
Christopher Topalian

COLLEGEOFSCRIPTING.WEEBLY.COM
CAMERA

College of Scripting Music & Science


Christopher Topalian
Camera OPEN our Webcam
import cv2

cv2.namedWindow("Howdy")

COLLEGEOFSCRIPTING.WEEBLY.COM
theVideo = cv2.VideoCapture(0)

rval, theFrame = theVideo.read()

while rval:
cv2.imshow("Howdy", theFrame)
rval, theFrame = theVideo.read()
key = cv2.waitKey(22)

This script opens a new window with our


Web Camera as the video source!
College of Scripting Music & Science
Christopher Topalian
Camera OPEN Webcam, with Close
import cv2
cv2.namedWindow("Howdy")
theVideo = cv2.VideoCapture(0)

COLLEGEOFSCRIPTING.WEEBLY.COM
if theVideo.isOpened():
rval, theFrame = theVideo.read()
else:
rval = False
while rval:
cv2.imshow("Howdy", theFrame)
rval, theFrame = theVideo.read()
key = cv2.waitKey(22)
if key == 27:
break
cv2.destroyWindow("Howdy")
College of Scripting Music & Science
Christopher Topalian

COLLEGEOFSCRIPTING.WEEBLY.COM
IMAGES

College of Scripting Music & Science


Christopher Topalian

Python Image Library

COLLEGEOFSCRIPTING.WEEBLY.COM
pip install pillow

College of Scripting Music & Science


Christopher Topalian
tkinter open image, using pillow
import tkinter as tk
from PIL import ImageTk, Image

ourWindow = tk.Tk()
ourWindow.geometry("670x525+100+100")

COLLEGEOFSCRIPTING.WEEBLY.COM
ourWindow.title("Our Image App")
ourWindow.configure(background='black')

ourTexture = Image.open("theTexture.png")
ourTexture = ImageTk.PhotoImage(ourTexture)

ourLabel = tk.Label(ourWindow, image = ourTexture)

ourLabel.pack(side = "top")

ourWindow.mainloop()

This script opens our


texture in our Window
College of Scripting Music & Science
Christopher Topalian
tkinter resize image, using pillow
import tkinter as tk
from PIL import ImageTk, Image

ourWindow = tk.Tk()
ourWindow.geometry("900x900+100+100")

COLLEGEOFSCRIPTING.WEEBLY.COM
ourWindow.title("Our Image App")
ourWindow.configure(background='black')

ourTexture = Image.open("theTexture.png")
ourTexture = ourTexture.resize((800,800))
ourTexture = ImageTk.PhotoImage(ourTexture)

ourLabel = tk.Label(ourWindow, image = ourTexture)

ourLabel.pack(side = "top")

ourWindow.mainloop()

This script opens


our resized texture
in our Window College of Scripting Music & Science
Christopher Topalian
tkinter position image, using pillow
import tkinter as tk
from PIL import ImageTk, Image

ourWindow = tk.Tk()
ourWindow.geometry("900x900+100+100")

COLLEGEOFSCRIPTING.WEEBLY.COM
ourWindow.title("Our Image App")
ourWindow.configure(background='black')

ourTexture = Image.open("theTexture.png")
ourTexture = ourTexture.resize((700,700))
ourTexture = ImageTk.PhotoImage(ourTexture)

ourLabel = tk.Label(ourWindow, image = ourTexture)

ourLabel.place(x = 0, y = 0)

ourWindow.mainloop()

This script opens our


positioned texture in
our Window
College of Scripting Music & Science
Christopher Topalian
tkinter rotate image, using pillow
import tkinter as tk
from PIL import ImageTk, Image

ourWindow = tk.Tk()
ourWindow.geometry("650x550+100+100")

COLLEGEOFSCRIPTING.WEEBLY.COM
ourWindow.title("Our Image App")
ourWindow.configure(background='black')

ourTexture = Image.open("theTexture.png")
ourTexture = ourTexture.rotate((180))
ourTexture = ImageTk.PhotoImage(ourTexture)

ourLabel = tk.Label(ourWindow, image = ourTexture)

ourLabel.pack(side = "top")

ourWindow.mainloop()

This script opens our


rotated texture in our
Window
College of Scripting Music & Science
open image using pillow
Christopher Topalian

from PIL import Image


ourTexture = Image.open("theTexture.png")
ourTexture.show()

COLLEGEOFSCRIPTING.WEEBLY.COM
ourScript.py is in the
SAME FOLDER as Opens our Texture
theTexture.png using our
Default Image App
College of Scripting Music & Science
rotate image, using pillow Christopher Topalian

from PIL import Image

ourTexture = Image.open("theTexture.png")

COLLEGEOFSCRIPTING.WEEBLY.COM
ourTexture.rotate(180).show()

ourScript.py is in the Opens and Rotates


SAME FOLDER as our Texture
theTexture.png using our
Default Image App
College of Scripting Music & Science
Christopher Topalian

COLLEGEOFSCRIPTING.WEEBLY.COM
SCREEN
SHOT

College of Scripting Music & Science


Christopher Topalian
Screenshot Full Screen using pillow
from PIL import ImageGrab

ourImage = ImageGrab.grab()

COLLEGEOFSCRIPTING.WEEBLY.COM
ourImage.save('ourNewTexture.png')

We use the grab


function to take this
screen shot and save
it as a .png file
named ourTexture
The texture is created in
the location folder where
this script is activated.

College of Scripting Music & Science


Christopher Topalian
Screenshot Part of Screen using pillow
y height
from PIL import ImageGrab x
width

ourImage = ImageGrab.grab(bbox=(0,0,900,800))

COLLEGEOFSCRIPTING.WEEBLY.COM
ourImage.save('ourNewTexture.png')

We use the grab


function to take this
screen shot and save
it as a .png file
named ourTexture

College of Scripting Music & Science


Christopher Topalian
Screenshot Full Screen, Repeatedly
from PIL import ImageGrab
import time

x=1
while x <= 5:

COLLEGEOFSCRIPTING.WEEBLY.COM
time.sleep(4.0)
x = x + 1;
ourImage = ImageGrab.grab()
ourImage.save("ourScreenshot" + str(x)+".png")

We grab a
screenshot
every
4 seconds
and repeat
the process
5 times.
College of Scripting Music & Science
Christopher Topalian

Keyboard Controls

COLLEGEOFSCRIPTING.WEEBLY.COM
pip install keyboard

College of Scripting Music & Science


Christopher Topalian
Screenshot by Keyboard Press
from PIL import ImageGrab
import keyboard

while True:
try:

COLLEGEOFSCRIPTING.WEEBLY.COM
if keyboard.is_pressed('enter'):
ourImage = ImageGrab.grab()
ourImage.save("ourTexture.png")
break
else:
pass
except: We grab a
break screenshot
by pressing
The screenshot
the Enter
is created in the
button on
folder where
our
this script is
Keyboard
activated from.
College of Scripting Music & Science
Christopher Topalian

COLLEGEOFSCRIPTING.WEEBLY.COM
SIMULATION

College of Scripting Music & Science


Christopher Topalian

Pygame to Make Games!

COLLEGEOFSCRIPTING.WEEBLY.COM
pip install pygame

College of Scripting Music & Science


Christopher Topalian
pygame – Window, Fill Color, Draw Circle
import pygame
pygame.init()
ourWindow =
pygame.display.set_mode( [500, 500] )

COLLEGEOFSCRIPTING.WEEBLY.COM
running = True
while running:
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
ourWindow.fill((0, 0, 0))
pygame.draw.circle(ourWindow, (0, 150,
255), (100, 100), 50)
pygame.display.flip()
pygame.quit()
College of Scripting Music & Science
Christopher Topalian
Type pip show nameOfPackage

COLLEGEOFSCRIPTING.WEEBLY.COM
pip show pygame
show INFO
about ANY
module that we
have already
installed!

Shows location
of the package
College of Scripting Music & Science
Christopher Topalian
Highlight
the
Location Press
of the Control + C
packages to Copy

COLLEGEOFSCRIPTING.WEEBLY.COM
Control + V to Paste the
location into the address
bar of any folder

We can now Open the


pygame folder, and
SEE all of the scripts
that make it work!

College of Scripting Music & Science


Christopher Topalian
Study the pygame Folder Contents

COLLEGEOFSCRIPTING.WEEBLY.COM
This is the pygame
package folder.
It shows all of the
scripts and other
items that make the
pygame package work

You can learn a lot


about how packages
are structured by
studying these folders

College of Scripting Music & Science


Christopher Topalian

COLLEGEOFSCRIPTING.WEEBLY.COM
VIDEO

College of Scripting Music & Science


Christopher Topalian

Movie Module

COLLEGEOFSCRIPTING.WEEBLY.COM
pip install moviepy

College of Scripting Music & Science


Christopher Topalian
pygame, moviepy, play movie, size by ratio
import moviepy
from moviepy.editor import *
import pygame

ourVid = VideoFileClip('testMovie.mp4').resize(0.3)

COLLEGEOFSCRIPTING.WEEBLY.COM
ourVid.preview()

pygame.quit()

Make sure to have


pygame
and
moviepy
installed,
as shown before.

College of Scripting Music & Science


Christopher Topalian
pygame, moviepy, play movie, size by x, y
import moviepy
from moviepy.editor import *
import pygame

x = 700

COLLEGEOFSCRIPTING.WEEBLY.COM
y = 500

ourVid = VideoFileClip('testMovie.mp4').resize((x, y))

ourVid.preview()

pygame.quit()

College of Scripting Music & Science


Christopher Topalian
pygame, moviepy, Start and End time

import moviepy
from moviepy.editor import *
import pygame

COLLEGEOFSCRIPTING.WEEBLY.COM
ourVid = VideoFileClip('testMovie.mp4').resize(1.4)

aPortion = ourVid.subclip(5, 20)

aPortion.preview()

pygame.quit()

College of Scripting Music & Science


Christopher Topalian
pygame, moviepy, slow motion
import moviepy
from moviepy.editor import *
import pygame

ourVid = VideoFileClip('testMovie.mp4').resize(1.4)

COLLEGEOFSCRIPTING.WEEBLY.COM
aPortion = ourVid.subclip(5, 20)
ourVid = aPortion.speedx(0.3)

ourVid.preview()

pygame.quit()

College of Scripting Music & Science


Christopher Topalian

COLLEGEOFSCRIPTING.WEEBLY.COM
Nested
Dictionaries

College of Scripting Music & Science


Christopher Topalian
Nested Dictionaries - Show All
import ctypes The Characters X
characters = { Superman
'Superman': Batman
{ OK
'location': 'Metropolis',

COLLEGEOFSCRIPTING.WEEBLY.COM
'planet': 'Krypton'
},
'Batman':
{
'location': 'Gotham',
'planet': 'Earth'
}
} Loop through all entries
answer = " " of our Nested Dictionaries
for z in characters:
answer += z + '\n'
ctypes.windll.user32.MessageBoxW(0,
answer, "The Characters", 0)
College of Scripting Music & Science
Christopher Topalian
Nested Dictionaries - Filter for String
import ctypes The Characters X
characters = {
'Superman': Superman
{ OK
'location': 'Metropolis',

COLLEGEOFSCRIPTING.WEEBLY.COM
'planet': 'Krypton'
},
'Batman':
{
'location': 'Gotham',
'planet': 'Earth'
}
}
only if location
answer = " " is Metropolis
for z in characters:
if (characters[z]['location'] == 'Metropolis') :
answer += z + '\n'
ctypes.windll.user32.MessageBoxW(0,
answer, "The Characters", 0)
College of Scripting Music & Science
Christopher Topalian
Nested Dictionaries in Window
from tkinter import *
characters = { Superman
'Superman':
{ Batman
'location': 'Metropolis',
'planet': 'Krypton'

COLLEGEOFSCRIPTING.WEEBLY.COM
},
'Batman':
{
'location': 'Gotham',
'planet': 'Earth'
} height y pos
} width x pos
ourWindow = Tk()
ourWindow.geometry('215x175+300+150')
ourWindow.title('Our App')
x = 75
Loop through all entries
y=5
of our Nested Dictionaries
for z in characters:
ourFirstLabel = Label(ourWindow,
text = z, fg = 'aqua', bg = 'black').place(x = x, y = y)
y += 40
ourWindow.mainloop()
College of Scripting Music & Science
Nested Dictionaries - MakeChristopher
Labels Topalian

from tkinter import *


periodicTable= {
'Copper':
{
Gold
'abbreviation': 'Cu',
'electrons': '29'
},

COLLEGEOFSCRIPTING.WEEBLY.COM
'Gold':
{
'abbreviation': 'Au',
'electrons': '79'
} height y pos
} width x pos
ourWindow = Tk()
ourWindow.geometry('220x175+200+100')
ourWindow.title('Elements')
x = 75 only if electrons
y=5 are more than 35
for z in periodicTable:
if (periodicTable[z]['electrons'] > '35' ):
ourFirstLabel = Label(ourWindow, text = z, fg = 'aqua',
bg = 'black').place(x = x, y = y)
y += 40
ourWindow.mainloop() College of Scripting Music & Science
Christopher Topalian
Nested Dictionaries - Show All
languages = { Console Version
'Javascript': Result
{ Title Javascript
'year': '1995', Created in 1995
'extension': '.js' Extension is .js

COLLEGEOFSCRIPTING.WEEBLY.COM
},
'Python': Title Python
Created in 1991
{ Extension is .py
'year': '1991',
'extension': '.py'
}
} Loop through all entries
of our Nested Dictionaries
for x in languages:
print('\nTitle', x)
print('Created in', languages[x]['year'])
print('Extension is', languages[x]['extension'])
input('Press Enter to Exit')

College of Scripting Music & Science


Christopher Topalian
Nested Dictionaries - Show All
periodicTable= { Console Version
'Silver': Result
{ Title: Silver
'abbreviation': 'Ag', Letters: Ag
'electrons': '47' Atomic # 47

COLLEGEOFSCRIPTING.WEEBLY.COM
},
Title: Iron
'Iron': Letters: Fe
{ Atomic #: 26
'abbreviation': 'Fe',
'electrons': '26'
} Loop through all entries
} of our Nested Dictionaries
for x in periodicTable:
print('\nTitle:', x)
print('Letters:', periodicTable[x]['abbreviation'])
print('Atomic #:', periodicTable[x]['electrons'])
input('Press Enter to Exit')

College of Scripting Music & Science


Christopher Topalian
Nested Dictionaries - Show All
periodicTable= { Console Version
'Copper':
{
'abbreviation': 'Cu',
'url': 'https://en.wikipedia.org/wiki/Copper',

COLLEGEOFSCRIPTING.WEEBLY.COM
'electrons': '29'
},
'Gold':
{
'abbreviation': 'Au',
'url': 'https://en.wikipedia.org/wiki/Gold',
'electrons': '79'
}
Loop through all entries
}
of our Nested Dictionaries
for x in periodicTable:
print('\nTitle:', x)
print('Letters', periodicTable[x]['abbreviation'])
print('Url', periodicTable[x]['url'])
print('Atomic Number', periodicTable[x]['electrons'])
input('Press Enter to Exit')
College of Scripting Music & Science
Christopher Topalian
Nested Dictionaries - Filter by Number
periodicTable= { Result is shown
'Copper':
{
on NEXT PAGE=>
'abbreviation': 'Cu',
'url': 'https://en.wikipedia.org/wiki/Copper',

COLLEGEOFSCRIPTING.WEEBLY.COM
'electrons': '29'
},
'Gold':
{
'abbreviation': 'Au',
'url': 'https://en.wikipedia.org/wiki/Gold',
'electrons': '79'
} Show if electrons
} are less than 75
for x in periodicTable:
if (periodicTable[x]['electrons'] < '75') :
print('\nTitle:', x)
print('Letters:', periodicTable[x]['abbreviation'])
print('Url:', periodicTable[x]['url'])
print('Atomic Number:', periodicTable[x]['electrons'])
input('Press Enter to Exit')
College of Scripting Music & Science
Christopher Topalian
Result of Previous Page Shown

COLLEGEOFSCRIPTING.WEEBLY.COM
Title: Copper
Letters: Cu
Url: https://en.wikipedia.org/wiki/Copper
Atomic Number: 29
College of Scripting Music & Science
Christopher Topalian
Nested Dictionaries - Filter by String
investigation = { Result also shown
'Suspect One': on NEXT PAGE=>
{
'name': 'John Doe', Result
'date': '2021/09/01 12:00 AM', Title: Suspect One
'location': 'Boston, MA' Name: John Doe

COLLEGEOFSCRIPTING.WEEBLY.COM
Date: 2021/09/01
}, 12:00 AM
'Suspect Two': Location: Boston, MA
{
'name': 'Jane Doe',
'date': '2020/08/12 12:00 AM',
'location': 'Denver, Colorado'
}
Show if location
}
is Boston, MA
for x in investigation:
if (investigation[x]['location'] == 'Boston, MA' ):
print('\nTitle:', x)
print('Name:', investigation[x]['name'])
print('Date:', investigation[x]['date'])
print('Location:', investigation[x]['location'])
input('Press Enter to Exit')
College of Scripting Music & Science
Christopher Topalian
Result of Previous Page Shown

COLLEGEOFSCRIPTING.WEEBLY.COM
College of Scripting Music & Science
Christopher Topalian
Nested Dictionaries - Filter by String
spyDevices = { Result
'Alexa': Title: Google Home
Company: Alphabet Inc
{ Date: 11/4/2016
'company': 'Amazon',
'date': '2014/11/06 12:00 AM'

COLLEGEOFSCRIPTING.WEEBLY.COM
},
'Google Home':
{
'company': 'Alphabet Inc',
'date': '2016/11/04 12:00 AM'
}
} Show if company
is NOT Amazon
for x in spyDevices:
if (spyDevices[x]['company'] != 'Amazon') :
print('\nTitle:', x)
print('Company', spyDevices[x]['company'])
print('Date', spyDevices[x]['date'])
input('Press Enter to Exit')
College of Scripting Music & Science
Christopher Topalian
Nested Dictionaries - Filter by String
collegeVideos= {
'Evidence Viewer for Investigators':
{
'date': '2020/09/15 12:00 AM',
'url': 'https://youtu.be/jMBKRbG_bXw',

COLLEGEOFSCRIPTING.WEEBLY.COM
'description': 'javascript'
},
'Evidence Application':
{
'date': '2020/09/13 12:00 AM',
'url': 'https://youtu.be/9QWhAHqxB_Q',
'description': 'javascript'
} Show if description
} is javascript
for x in collegeVideos:
if (collegeVideos[x]['description'] == 'javascript') :
print('\nTitle:', x)
print('Date', collegeVideos[x]['date'])
print('Url', collegeVideos[x]['url'])
print('Description', collegeVideos[x]['description'])
input('Press Enter to Exit')
College of Scripting Music & Science
Christopher Topalian

Filter

COLLEGEOFSCRIPTING.WEEBLY.COM
by DATE
LESS
THAN
College of Scripting Music & Science
Christopher Topalian
Nested Dictionaries - Filter by Date
videoGames = { Console Version
'Cities Skylines': Result
{ Title: Garry's Mod
'engine': 'Unity', Engine: Source
'date': '2015/03/15 12:00 AM' Date: 2004/12/24

COLLEGEOFSCRIPTING.WEEBLY.COM
},
'Garry\'s Mod': \' is used to escape
{ the apostrophe
'engine': 'Source',
'date': '2004/12/24 12:00 AM'
}
} Show if date is less
than 2005 March 14th
for x in videoGames:
if (videoGames[x]['date'] < '2005/03/14'):
print('\nTitle:', x)
print('Engine:', videoGames[x]['engine'])
print('Date:', videoGames[x]['date'])
input('Press Enter to Exit')
College of Scripting Music & Science
Christopher Topalian
Nested Dictionaries - Filter by Date
import ctypes Simulation X
videoGames = { Gary's Mod
'Cities Skylines': Source
{ 2004/12/24 12:00AM
'engine': 'Unity', OK

COLLEGEOFSCRIPTING.WEEBLY.COM
'date': '2015/03/15 12:00 AM'
}, MessageBoxW
'Garry\'s Mod': version
{ \' is used to
'engine': 'Source', escape the
'date': '2004/12/24 12:00 AM' apostrophe
}
} Show if date is less
answer = " " than 2005 March 14th
for z in videoGames:
if (videoGames[z]['date'] < '2005/03/14') :
answer += z + '\n'
answer += videoGames[z]['engine'] + '\n'
answer += videoGames[z]['date'] + '\n'
ctypes.windll.user32.MessageBoxW(0,
answer, "Simulation", 0)
College of Scripting Music & Science
Christopher Topalian

Filter by

COLLEGEOFSCRIPTING.WEEBLY.COM
DATE
GREATER
THAN
College of Scripting Music & Science
Christopher Topalian
Nested Dictionaries - Filter by Date
collegeVideos= { Console Version
'LSL Scripting Tutorial, How to Make a New Script':
{
'date': '2020/09/15 12:00 AM',
'url': 'https://youtu.be/JyTxamxK3E8',

COLLEGEOFSCRIPTING.WEEBLY.COM
'description': 'lsl scripting'
},
'Spreadsheets Become JS 2D VIRTUAL WORLDS':
{
'date': '2020/09/13 12:00 AM',
'url': 'https://youtu.be/CsijyVNLwQc',
'description': 'javascript'
} Show if date is greater
} than 2020 Sept 14th
for x in collegeVideos:
if (collegeVideos[x]['date'] > '2020/09/14') :
print('\nTitle:', x)
print('Date', collegeVideos[x]['date'])
print('Url', collegeVideos[x]['url'])
print('Description', collegeVideos[x]['description'])
input('Press Enter to Exit')
College of Scripting Music & Science
Christopher Topalian
Nested Dictionaries - Filter by Date
import ctypes MessageBoxW
collegeVideos= { version
'LSL Scripting Tutorial, How to Make a New Script':
{
'date': '2020/09/15 12:00 AM',

COLLEGEOFSCRIPTING.WEEBLY.COM
'url': 'https://youtu.be/JyTxamxK3E8',
},
'Spreadsheets Become JS 2D VIRTUAL WORLDS':
{
'date': '2020/09/13 12:00 AM',
'url': 'https://youtu.be/CsijyVNLwQc',
}
} Show if date is greater
answer = " " than 2020 Sept 14th
for z in collegeVideos:
if (collegeVideos[z]['date'] > '2020/09/14') :
answer += z + ' '
answer += collegeVideos[z]['date'] + '\n'
answer += collegeVideos[z]['url'] + '\n'
ctypes.windll.user32.MessageBoxW(0,
answer, "The College Videos", 0)
College of Scripting Music & Science
Christopher Topalian

ADD

COLLEGEOFSCRIPTING.WEEBLY.COM
Nested
Dictionary

College of Scripting Music & Science


Christopher Topalian
Nested Dictionaries - ADD Dictionary
periodicTable= { Result
'Copper':
Title: Copper
{ Letters: Cu
'abbreviation': 'Cu', Atomic #: 29
'electrons': '29'
}, Title: Gold

COLLEGEOFSCRIPTING.WEEBLY.COM
Letters: Au
'Gold': Atomic #: 79
{
'abbreviation': 'Au', Title: Platinum
'electrons': '79' Letters: Pt
} Atomic #: 78
Add Dictionary
} console
periodicTable['Platinum'] = { version
'abbreviation': 'Pt',
'electrons': '78'
} Loop through all entries
for x in periodicTable: of our Nested Dictionaries
print('\nTitle:', x)
print('Letters:', periodicTable[x]['abbreviation'])
print('Atomic #:', periodicTable[x]['electrons'])
input('Press Enter to Exit')
College of Scripting Music & Science
Christopher Topalian
Nested Dictionaries - ADD Dictionary
import ctypes
periodicTable= { The Elements X
'Copper': Copper Cu: 29
{ Gold Au: 79
'abbreviation': 'Cu', Platinum Pt: 78
'electrons': '29' OK

COLLEGEOFSCRIPTING.WEEBLY.COM
},
'Gold': MessageBoxW
{ version
'abbreviation': 'Au',
'electrons': '79'
} Add Dictionary
}
periodicTable['Platinum'] = {
'abbreviation': 'Pt',
'electrons': '78'
}
answer = " "
for z in periodicTable:
answer += z + ' '
answer += periodicTable[z]['abbreviation'] + ': '
answer += periodicTable[z]['electrons'] + '\n'
ctypes.windll.user32.MessageBoxW(0,
answer, "The Elements", 0) College of Scripting Music & Science
Christopher Topalian

DELETE

COLLEGEOFSCRIPTING.WEEBLY.COM
Nested
Dictionary

College of Scripting Music & Science


Christopher Topalian
Nested Dictionaries - Delete Dictionary
periodicTable= { Result
'Copper': Title: Copper
{ Letters: Cu
'abbreviation': 'Cu', Atomic #: 29
'electrons':'29'
console

COLLEGEOFSCRIPTING.WEEBLY.COM
},
'Gold': version
{
'abbreviation': 'Au',
'electrons':'79'
}
Delete Dictionary
}
del periodicTable['Gold']
Loop through all entries
for x in periodicTable: of our Nested Dictionaries
print('\nTitle:', x)
print('Letters:', periodicTable[x]['abbreviation'])
print('Atomic #:', periodicTable[x]['electrons'])
input('Press Enter to Exit')

College of Scripting Music & Science


Christopher Topalian
Nested Dictionaries - Delete Dictionary
import ctypes The Elements X
periodicTable= {
Copper Cu: 29
'Copper':
{
OK
'abbreviation': 'Cu',

COLLEGEOFSCRIPTING.WEEBLY.COM
'electrons': '29'
}, MessageBoxW
'Gold': version
{
'abbreviation': 'Au',
'electrons': '79'
} Delete Dictionary
}
del periodicTable['Gold']
answer = " "
for z in periodicTable:
answer += z + ' '
answer += periodicTable[z]['abbreviation'] + ': '
answer += periodicTable[z]['electrons'] + '\n'
ctypes.windll.user32.MessageBoxW(0,
answer, "The Elements", 0)
College of Scripting Music & Science
Christopher Topalian

DELETE
Last Entry

COLLEGEOFSCRIPTING.WEEBLY.COM
of a
Nested
Dictionary
College of Scripting Music & Science
Nested Dictionaries - Delete LastChristopher
Dictionary Topalian

periodicTable= { Result
'Copper': Title: Copper
{ Letters: Cu
'abbreviation': 'Cu', Atomic #: 29
'electrons': '29'
console

COLLEGEOFSCRIPTING.WEEBLY.COM
},
'Gold': version
{
'abbreviation': 'Au',
'electrons': '79'
}
} Delete Last Entry

periodicTable.popitem()
Loop through all entries
for x in periodicTable: of our Nested Dictionaries
print('\nTitle:', x)
print('Letters:', periodicTable[x]['abbreviation'])
print('Atomic #:', periodicTable[x]['electrons'])
input('Press Enter to Exit')

College of Scripting Music & Science


Christopher Topalian
Nested Dictionaries - Delete Last Dictionary
import ctypes The Elements X
periodicTable= {
Copper Cu: 29
'Copper':
{
OK
'abbreviation': 'Cu',

COLLEGEOFSCRIPTING.WEEBLY.COM
'electrons': '29'
}, MessageBoxW
'Gold': version
{
'abbreviation': 'Au',
'electrons': '79'
}
} Delete Last Entry
periodicTable.popitem()
answer = " " Loop through all entries
for z in periodicTable: of our Nested Dictionaries
answer += z + ' '
answer += periodicTable[z]['abbreviation'] + ': '
answer += periodicTable[z]['electrons'] + '\n'
ctypes.windll.user32.MessageBoxW(0,
answer, "The Elements", 0)
College of Scripting Music & Science
Christopher Topalian

DELETE
First Entry

COLLEGEOFSCRIPTING.WEEBLY.COM
of a
Nested
Dictionary
College of Scripting Music & Science
Christopher Topalian
Nested Dictionaries - Delete 1st Dictionary pop
periodicTable= { Result
'Copper': Title: Gold
{ Letters: Au
'abbreviation': 'Cu', Atomic #: 79
'electrons': '29'
console

COLLEGEOFSCRIPTING.WEEBLY.COM
},
'Gold':
version
{
'abbreviation': 'Au',
'electrons': '79'
}
Delete First Entry
}
periodicTable.pop(list(periodicTable)[0])
for x in periodicTable:
print('\nTitle:', x)
print('Letters:', periodicTable[x]['abbreviation'])
print('Atomic #:', periodicTable[x]['electrons'])
input('Press Enter to Exit')

College of Scripting Music & Science


Christopher Topalian
Nested Dictionaries - Delete 1st Dictionary pop
import ctypes The Elements X
periodicTable= {
Gold Au: 79
'Copper':
{
OK
'abbreviation': 'Cu',

COLLEGEOFSCRIPTING.WEEBLY.COM
'electrons': '29'
}, MessageBoxW
'Gold': version
{
'abbreviation': 'Au',
'electrons': '79'
} Delete First Entry
}
periodicTable.pop(list(periodicTable)[0])
answer = " "
for z in periodicTable:
answer += z + ' '
answer += periodicTable[z]['abbreviation'] + ': '
answer += periodicTable[z]['electrons'] + '\n'
ctypes.windll.user32.MessageBoxW(0,
answer, "The Elements", 0)
College of Scripting Music & Science
Christopher Topalian
Nested Dictionaries - Delete 1st Dictionary del
periodicTable= { Result
'Copper': Title: Gold
{ Letters: Au
'abbreviation': 'Cu', Atomic #: 79
'electrons':'29'
console

COLLEGEOFSCRIPTING.WEEBLY.COM
},
'Gold': version
{
'abbreviation': 'Au',
'electrons':'79'
} Delete First Entry
}
del periodicTable[ list(periodicTable)[0] ]
for x in periodicTable:
print('\nTitle:', x)
print('Letters:', periodicTable[x]['abbreviation'])
print('Atomic #:', periodicTable[x]['electrons'])
input('Press Enter to Exit')

College of Scripting Music & Science


Christopher Topalian
Nested Dictionaries - Delete 1st Dictionary del
import ctypes The Elements X
periodicTable= {
'Copper': Gold Au: 79
{
'abbreviation': 'Cu', OK

COLLEGEOFSCRIPTING.WEEBLY.COM
'electrons': '29'
}, MessageBoxW
'Gold': version
{
'abbreviation': 'Au',
'electrons': '79'
} Delete First Entry
}
del periodicTable[ list(periodicTable)[0] ]
answer = " "
for z in periodicTable:
answer += z + ' '
answer += periodicTable[z]['abbreviation'] + ': '
answer += periodicTable[z]['electrons'] + '\n'
ctypes.windll.user32.MessageBoxW(0,
answer, "The Elements", 0)
College of Scripting Music & Science
Christopher Topalian

DELETE
Second Entry

COLLEGEOFSCRIPTING.WEEBLY.COM
of a
Nested
Dictionary
College of Scripting Music & Science
Christopher Topalian
Nested Dictionaries - Delete 2nd Dictionary pop
periodicTable= { Result
'Copper': Title: Copper
{ Letters: Cu
Atomic #: 29
'abbreviation': 'Cu',
'electrons':'29' console

COLLEGEOFSCRIPTING.WEEBLY.COM
}, version
'Gold':
{
'abbreviation': 'Au',
'electrons':'79'
} Delete Second Entry
}
periodicTable.pop(list(periodicTable)[1])
for x in periodicTable:
print('\nTitle:', x)
print('Letters:', periodicTable[x]['abbreviation'])
print('Atomic #:', periodicTable[x]['electrons'])
input('Press Enter to Exit')
College of Scripting Music & Science
Christopher Topalian
Nested Dictionaries - Delete 2nd Dictionary pop
import ctypes The Elements X
periodicTable= {
'Copper': Copper Cu: 29
{
OK
'abbreviation': 'Cu',

COLLEGEOFSCRIPTING.WEEBLY.COM
'electrons': '29'
}, MessageBoxW
'Gold': version
{
'abbreviation': 'Au',
'electrons': '79'
} Delete Second Entry
}
periodicTable.pop(list(periodicTable)[1])
answer = " "
for z in periodicTable:
answer += z + ' '
answer += periodicTable[z]['abbreviation'] + ': '
answer += periodicTable[z]['electrons'] + '\n'
ctypes.windll.user32.MessageBoxW(0,
answer, "The Elements", 0)
College of Scripting Music & Science
Christopher Topalian

EDIT
an Entry

COLLEGEOFSCRIPTING.WEEBLY.COM
by Index
Nested
Dictionary
College of Scripting Music & Science
Christopher Topalian
Nested Dictionaries - Edit Dictionary by Index
periodicTable= { Result
'Copper': Title: Copper
{ Letters: Cuprum
'abbreviation': 'Cu', Atomic #: Twenty Nine
'electrons':'29' Title: Gold

COLLEGEOFSCRIPTING.WEEBLY.COM
}, Letters: Au
'Gold': Atomic #: 79
{
'abbreviation': 'Au', console
'electrons':'79' version
} Edit Data of first entry
}
periodicTable[ list(periodicTable)[0] ]= {
'abbreviation':'Cupric', 'electrons':'Twenty Nine' }
for x in periodicTable:
print('\nTitle:', x)
print('Letters:', periodicTable[x]['abbreviation'])
print('Atomic #:', periodicTable[x]['electrons'])
input('Press Enter to Exit')

College of Scripting Music & Science


Christopher Topalian
Nested Dictionaries - Edit Dictionary by Index
import ctypes The Elements X
periodicTable= {
'Copper': Copper Cuprum: 29
{ Gold Au: 79
'abbreviation': 'Cu',
OK
'electrons': '29'

COLLEGEOFSCRIPTING.WEEBLY.COM
},
'Gold': MessageBoxW
{ version
'abbreviation': 'Au',
'electrons': '79'
} Edit Data of first entry
}
periodicTable[ list(periodicTable)[0] ]= {
'abbreviation':' Cuprum',
'electrons':' Twenty Nine' }
answer = " "
for z in periodicTable:
answer += z + ' '
answer += periodicTable[z]['abbreviation'] + ': '
answer += periodicTable[z]['electrons'] + '\n'
ctypes.windll.user32.MessageBoxW(0,
answer, "The Elements", 0)College of Scripting Music & Science
Christopher Topalian

EDIT
an Entry

COLLEGEOFSCRIPTING.WEEBLY.COM
by Key
Nested
Dictionary
College of Scripting Music & Science
Christopher Topalian
Nested Dictionaries - Edit Dictionary by Key
periodicTable= {
'Copper':
Result
Title: Copper
{ Letters: Cuprum
'abbreviation': 'Cu', Atomic #: Twenty Nine
'electrons': '29'
}, Title: Gold

COLLEGEOFSCRIPTING.WEEBLY.COM
'Gold': Letters: Au
Atomic #: 79
{
'abbreviation': 'Au', console
'electrons': '79'
Edit Data of
version
}
} Copper entry
periodicTable['Copper'] = {
'abbreviation':'Cuprum',
'electrons':'Twenty Nine'
} Loop through all entries
for x in periodicTable: of our Nested Dictionaries
print('\nTitle:', x)
print('Letters:', periodicTable[x]['abbreviation'])
print('Atomic #:', periodicTable[x]['electrons'])
input('Press Enter to Exit')
College of Scripting Music & Science
Christopher Topalian
Nested Dictionaries - Edit Dictionary by Key
import ctypes The Elements X
periodicTable= {
'Copper': Copper Cuprum: 29
{ Gold Au: 79
'abbreviation': 'Cu',
OK
'electrons': '29'

COLLEGEOFSCRIPTING.WEEBLY.COM
},
'Gold': MessageBoxW
{ version
'abbreviation': 'Au',
'electrons': '79'
}
}
periodicTable['Copper'] = {
'abbreviation':' Cuprum', Edit Copper
'electrons':' Twenty Nine' abbreviation
}
answer = " "
for z in periodicTable:
answer += z + ' '
answer += periodicTable[z]['abbreviation'] + ': '
answer += periodicTable[z]['electrons'] + '\n'
ctypes.windll.user32.MessageBoxW(0,
answer, "The Elements", 0)
College of Scripting Music & Science
Nested Dictionaries - Edit ValueChristopher
by Key Topalian

periodicTable= { Result
'Copper': Title: Copper
{ Letters:
'abbreviation': 'Cu', Atomic #: 29
'electrons': '29' Title: Gold

COLLEGEOFSCRIPTING.WEEBLY.COM
}, Letters: Au
'Gold': Atomic #: 79
{
'abbreviation': 'Au',
console
'electrons': '79'
version
} Edit Copper
} abbreviation

periodicTable['Copper']['abbreviation'] = ' '

for x in periodicTable: empty string


print('\nTitle:', x)
print('Letters:', periodicTable[x]['abbreviation'])
print('Atomic #:', periodicTable[x]['electrons'])
input('Press Enter to Exit')

College of Scripting Music & Science


Christopher Topalian
Nested Dictionaries - Edit Value by Key
import ctypes The Elements X
periodicTable= {
Copper: 29
'Copper':
Gold Au: 79
{
'abbreviation': 'Cu', OK

COLLEGEOFSCRIPTING.WEEBLY.COM
'electrons': '29'
}, MessageBoxW
'Gold': Version
{
'abbreviation': 'Au',
'electrons': '79' Edit Copper
} abbreviation
}
periodicTable['Copper']['abbreviation'] = ' '
answer = " "
for z in periodicTable: empty string
answer += z + ' '
answer += periodicTable[z]['abbreviation'] + ': '
answer += periodicTable[z]['electrons'] + '\n'
ctypes.windll.user32.MessageBoxW(0,
answer, "The Elements", 0) College of Scripting Music & Science
Christopher Topalian

Nested
Dictionaries

COLLEGEOFSCRIPTING.WEEBLY.COM
using
or
to Filter using
Multiple
Criteria
College of Scripting Music & Science
Christopher Topalian
Nested Dictionaries - Filter for A or B
import ctypes The Elements X
elements = { Zinc
'Zinc': Silver
{
OK
'electrons': '30',

COLLEGEOFSCRIPTING.WEEBLY.COM
'type': 'metal'
show if
}, electrons
'Silver': has 30 or 47
{
'electrons': '47',
'type': 'metal'
}
} show only if electrons
answer = " " has 30 or 47
for z in elements:
if (elements[z]['electrons'] == '30'
or elements[z]['electrons'] =='47'):
answer += z + '\n'
ctypes.windll.user32.MessageBoxW(0,
answer, "The Elements", 0)
College of Scripting Music & Science
Christopher Topalian
Nested Dictionaries - Filter for A or B
import ctypes The Movies X
movies = { Rocky 3
'Rocky 3': Superman 3
{
OK
'kind': 'action',

COLLEGEOFSCRIPTING.WEEBLY.COM
'date': '1982/05/28 12:00 AM'
show if kind
}, is action or
'Superman 3': adventure
{
'kind': 'adventure',
'date': '1983/06/17 12:00 AM'
}
} kind
answer = " " action kind
for z in movies: adventure
if (movies[z]['kind'] == 'action'
or movies[z]['kind'] == 'adventure'):
answer += z + '\n'
ctypes.windll.user32.MessageBoxW(0,
answer, "The Movies", 0)
College of Scripting Music & Science
Christopher Topalian

Nested
Dictionaries

COLLEGEOFSCRIPTING.WEEBLY.COM
using
and
to Filter using
Multiple
Criteria
College of Scripting Music & Science
Christopher Topalian
Nested Dictionaries - Filter for A and B
import ctypes The Movies X
movies = {
'Super Mario Bros': Super Mario Bros
{
OK
'type': 'comedy',

COLLEGEOFSCRIPTING.WEEBLY.COM
'date': '1993/05/28 12:00 AM'
}, show if date
is between
'Superman 1': start date
{ and end date
'type': 'adventure',
'date': '1978/12/15 12:00 AM'
}
} start date
answer = " " 1979/01/01 end date
for z in movies: 1995/01/01
if (movies[z]['date'] > '1979/01/01'
and movies[z]['date'] < '1995/01/01'):
answer += z + '\n'
ctypes.windll.user32.MessageBoxW(0,
answer, "The Movies", 0)
College of Scripting Music & Science
Nested Dictionaries - Filter forChristopher
A and Topalian
B
import ctypes The Speakers X
speakers = {
'Jane Doe': Jane Doe
{
OK
'title': 'Genetics Lecture',

COLLEGEOFSCRIPTING.WEEBLY.COM
'date': '2022/04/20 07:00 AM' show if Year,
}, Month, Day,
'John Doe': Time is
{ between
'title': 'Biology Innovations', start and end
'date': '2022/04/20 11:00 AM' condition
}
} if greater than
2022/04/20
answer = " " 05:00 AM
for z in speakers:
if (speakers[z]['date'] > '2022/04/20 05:00 AM'
and speakers[z]['date'] < '2022/04/20 10:00 AM'):
answer += z + '\n'
ctypes.windll.user32.MessageBoxW(0, if less than
2022/04/20
answer, "The Speakers", 0) 10:00 AM
College of Scripting Music & Science
Nested Dictionaries - Filter forChristopher
A and Topalian
B
import ctypes The Movies X
movies = {
'Independence Day': Independence Day
{
OK
'kind': 'action',

COLLEGEOFSCRIPTING.WEEBLY.COM
'date': '1996/07/03 12:00 AM'
}, show if date
is between
'Star Trek First Contact': start date
{ and end date
'kind': 'fantasy',
'date': '1996/11/22 12:00 AM'
}
} kind if date
answer = " " action less than
for z in movies: 1996/10/01
if (movies[z]['kind'] == 'action'
and movies[z]['date'] < '1996/10/01'):
answer += z + '\n'
ctypes.windll.user32.MessageBoxW(0,
answer, "The Movies", 0)
College of Scripting Music & Science
Christopher Topalian

COMBINE

COLLEGEOFSCRIPTING.WEEBLY.COM
Nested
Dictionaries

College of Scripting Music & Science


Nested Dictionaries - Combine Dictionaries
Christopher Topalian

import ctypes Result


speakersUSA = { Title: Jane Doe
'Jane Doe': Lecture: Genetics
{ Lecture
'title': 'Genetics Lecture', Date: 2022/04/20
'date': '2022/04/20 07:00 AM' 07:00 AM

COLLEGEOFSCRIPTING.WEEBLY.COM
} Title: Rose Doe
} Lecture: Botany
speakersEU = { Lecture
'Rose Doe': Date: 2022/04/20
{ 11:00 AM
'title': 'Botany Lecture',
'date': '2022/04/20 11:00 AM'
} ADD
Dictionary
}
speakersUSA.update(speakersEU)
for x in speakersUSA:
print('\nTitle:', x)
print('Lecture:', speakersUSA[x]['title'])
print('Date:', speakersUSA[x]['date'])
input('Press Enter to Exit')
College of Scripting Music & Science
Nested Dictionaries - Combine Dictionaries
Christopher Topalian

import ctypes The Speakers X

speakersUSA = { Jane Doe


'Jane Doe': Rose Doe
{ OK
'title': 'Genetics Lecture',

COLLEGEOFSCRIPTING.WEEBLY.COM
'date': '2022/04/20 07:00 AM'
}
}
speakersEU = {
'Rose Doe':
{
'title': 'Botany Lecture',
'date': '2022/04/20 11:00 AM' Added
} Dictionary
}
speakersUSA.update(speakersEU)
answer = " "
for z in speakersUSA:
answer += z + '\n'
ctypes.windll.user32.MessageBoxW(0,
answer, "The Speakers", 0)
College of Scripting Music & Science
Nested Dictionaries - Combine Dictionaries
Christopher Topalian

import ctypes Result is shown


speakersUSA = {
'Jane Doe': on NEXT PAGE=>
{
'title': 'Genetics Lecture', Each Dictionary
can have as many
'date': '2022/04/20 07:00 AM' entries as we want.

COLLEGEOFSCRIPTING.WEEBLY.COM
}
} In this tutorial we
speakersEU = { show only
'Rose Doe': one entry per
{ dictionary to keep
'title': 'Botany Lecture', text easy to read.
'date': '2022/04/20 11:00 AM'
} Added
} Dictionary
speakersUSA.update(speakersEU)
answer = " "
for z in speakersUSA:
answer += z + ' '
answer += speakersUSA[z]['title'] + ': '
answer += speakersUSA[z]['date'] + '\n'
ctypes.windll.user32.MessageBoxW(0,
answer, "The Speakers", 0)
College of Scripting Music & Science
Christopher Topalian
COPY the RESULT of our Message Box
The Speakers X

Jane Doe Genetics Lecture 2022/04/20 07:00 AM


Rose Doe Botany Lecture: 2022/04/20 11:00AM
OK

COLLEGEOFSCRIPTING.WEEBLY.COM
We Left Click our Mouse Arrow
anywhere on the Message Box.
We then press Ctrl + C to COPY.
We hear a sound, which indicates the action.
We can now paste the copied text
into ANY text editor for easy viewing,
pressing Ctrl + V to PASTE.
---------------------------
The Speakers
---------------------------
Jane Doe Genetics Lecture: 2022/04/20 07:00 AM
Rose Doe Botany Lecture: 2022/04/20 11:00 AM
---------------------------
OK
--------------------------- College of Scripting Music & Science
Nested Dictionaries - Combine Dictionaries
Christopher Topalian

import ctypes
speakersUSA = { The Speakers X
'Jane Doe': Jane Doe
{
'title': 'Genetics Lecture', John Doe
'date': '2022/04/20 07:00 AM' Rose Doe
}, Ronald Doe
'John Doe':

COLLEGEOFSCRIPTING.WEEBLY.COM
{ OK
'title': 'Mechanics Lecture',
'date': '2022/04/20 09:00 AM'
} We have added
} more entries
speakersEU = { to each dictionary,
'Rose Doe':
{ but the data is
'title': 'Botany Lecture', starting to take up
'date': '2022/04/20 11:00 AM' a lot of space!
},
'Ronald Doe': In the Next tutorial,
{
'title': 'Electronics Lecture', we put our DATA in
'date': '2022/04/20 01:00 PM' an EXTERNAL FILE,
} for easy readability!
}
speakersUSA.update(speakersEU)
answer = " "
for z in speakersUSA: Added Dictionary
answer += z + '\n'
ctypes.windll.user32.MessageBoxW(0,
answer, "The Speakers", 0) College of Scripting Music & Science
Christopher Topalian

EXTERNAL

COLLEGEOFSCRIPTING.WEEBLY.COM
FILE
Example

College of Scripting Music & Science


Christopher Topalian
Our External Data File saved as ourData.py
speakersUSA = {
'Jane Doe': We save this
{ script as
'title': 'Genetics Lecture', ourData.py
'date': '2022/04/20 07:00 AM'
},

COLLEGEOFSCRIPTING.WEEBLY.COM
'John Doe': On the next
{ tutorial page,
'title': 'Mechanics Lecture', the script
'date': '2022/04/20 09:00 AM' named
} ourScript.py
} uses the data
speakersEU = { from this page.
'Rose Doe':
{
'title': 'Botany Lecture', We place BOTH
'date': '2022/04/20 11:00 AM' ourData.py
}, and
'Ronald Doe': ourScript.py
{ in the
'title': 'Electronics Lecture', SAME
'date': '2022/04/20 01:00 PM' FOLDER!
}
}
College of Scripting Music & Science
Christopher Topalian
First Way of using ourData.py
import ctypes
from ourData import*
speakersUSA.update(speakersEU)
answer = " "
for z in speakersUSA:

COLLEGEOFSCRIPTING.WEEBLY.COM
answer += z + '\n'
ctypes.windll.user32.MessageBoxW(0,
answer, "The Speakers", 0)

We save this This script


USES the DATA
script as from the
ourScript.py previous page!

We place BOTH Double Click


ourScript.py ourScript.py
and and notice
ourData.py how it USES
in the the Data from
SAME FOLDER! ourData.py
College of Scripting Music & Science
Christopher Topalian
Second Way of using ourData.py
import ctypes, ourData
ourData.speakersUSA.update(ourData.speakersEU)
answer = " "
Dot is used to
for z in ourData.speakersUSA: access the data

COLLEGEOFSCRIPTING.WEEBLY.COM
answer += z + '\n'
ctypes.windll.user32.MessageBoxW(0,
answer, "The Speakers", 0)

We save this This script


USES the DATA
script as from the
ourScript.py previous page!

We place BOTH Double Click


ourScript.py ourScript.py
and and notice
ourData.py how it USES
in the the Data from
SAME FOLDER! ourData.py
College of Scripting Music & Science
Christopher Topalian

EXTERNAL

COLLEGEOFSCRIPTING.WEEBLY.COM
FILE
Example

College of Scripting Music & Science


Christopher Topalian
Save this data script as ourData.py
periodicTable= { We save this
'Copper': data script as
{ ourData.py
'abbreviation': 'Cu',
This is the

COLLEGEOFSCRIPTING.WEEBLY.COM
'electrons': '29' data that the
}, script on the
'Gold': next page will
{ reference!
'abbreviation': 'Au',
'electrons': '79'
}
}

The Script on the next page


uses this data!
Make sure both scripts
are located in the same folder.
College of Scripting Music & Science
Christopher Topalian
from tkinter import * Window
from ourData import* height y pos shows data
width x pos after button
ourWindow = Tk() is pressed
ourWindow.geometry('220x175+200+100')
ourWindow.title('Elements')
This script

COLLEGEOFSCRIPTING.WEEBLY.COM
theX = '' uses the
theY = '' file from
the
def ourFunction(): previous
theX = 65 page
theY = 5 named
for z in periodicTable: ourData.py
if (periodicTable[z]['electrons'] > '27' ):
ourLabel = Label(ourWindow, text = z, fg = 'aqua',
bg = 'black', font=("Courier", 25)).place(x=theX,y=theY)
theY += 40

ourButton = Button(ourWindow,
text = 'Show Elements', Both
command = ourFunction, Scripts
fg = 'white', bg = 'black').place(x = 65, y = 120) are in the
Same
ourWindow.mainloop() Folder
College of Scripting Music & Science
Christopher Topalian

Next page

COLLEGEOFSCRIPTING.WEEBLY.COM
shows why
separating
Data from
Code is Useful

College of Scripting Music & Science


from tkinter import * Christopher Topalian
periodicTable= { Window shows data
'Copper':
{ after button is pressed
'abbreviation': 'Cu',
'electrons': '29'
}, As more data is
'Gold': added, it becomes
{ more obvious why

COLLEGEOFSCRIPTING.WEEBLY.COM
'abbreviation': 'Au', using an external
'electrons': '79'
} file is a good
} choice.
ourWindow = Tk()
ourWindow.geometry('220x175+200+100')
ourWindow.title('Elements') This page shows
theX = ''
theY = '' the original script
def ourFunction(): that we had turned
theX = 65 into two files on the
theY = 5
for z in periodicTable: previous pages.
if (periodicTable[z]['electrons'] > '27' ):
ourLabel = Label(ourWindow, text = z, fg = 'aqua',
bg = 'black', font=("Courier", 25)).place(x=theX,y=theY)
theY += 40
ourButton = Button(ourWindow,
text = 'Show Elements',
command = ourFunction,
fg = 'white', bg = 'black').place(x = 65, y = 120)
ourWindow.mainloop() College of Scripting Music & Science
Christopher Topalian

Down

COLLEGEOFSCRIPTING.WEEBLY.COM
Down
Menu

College of Scripting Music & Science


Christopher Topalian
Drop Down Menu
from tkinter import * MONTHS
theMonths = [
'January','February','March','April',
'May','June','July', 'August', 'September',
'October', 'November', 'December'

COLLEGEOFSCRIPTING.WEEBLY.COM
]
ourWindow = Tk()
theChoice = StringVar(ourWindow)
theChoice.set(theMonths[0])
theDropDownMenu = OptionMenu(ourWindow,
theChoice, *theMonths)
theDropDownMenu.pack()
def ConfirmIt():
print(theChoice.get() + ' is the month chosen')
ourButton1 = Button(ourWindow,
text = "Select", command = ConfirmIt)
ourButton1.pack()
ourWindow.mainloop()
College of Scripting Music & Science
Christopher Topalian

COLLEGEOFSCRIPTING.WEEBLY.COM
LOGIC
College of Scripting Music & Science
Christopher Topalian

AND
from ctypes import* AB
0 0=0
A=1 0 1=0
1 0=0

COLLEGEOFSCRIPTING.WEEBLY.COM
B=1 1 1=1
if (A == 1 and B == 1):
print('Both True')
windll.user32.MessageBoxW(0,
'Both True', 'AND Gate', 0)
input('Press Enter to Exit')

Activates Only if
Both True
College of Scripting Music & Science
Christopher Topalian

NAND
AB
from ctypes import* 0 0=1
A=0 0 1=1
1 0=1

COLLEGEOFSCRIPTING.WEEBLY.COM
B=0 1 1=0
if (A == 0 or B == 0):
print('Both False or A True or B True')
windll.user32.MessageBoxW(0,
'Both False or A True or B True', 'NAND', 0)
input('Press Enter to Exit')

Activates Only if
Both False or
A True or B True
College of Scripting Music & Science
Christopher Topalian

OR
from ctypes import* AB
0 0=0
A=1 0 1=1
1 0=1

COLLEGEOFSCRIPTING.WEEBLY.COM
B=0 1 1=1
if (A == 1 or B == 1):
print('One or Both True')
windll.user32.MessageBoxW(0,
'One or Both True', 'OR Gate', 0)
input('Press Enter to Exit')

Activates Only if
One or Both True
College of Scripting Music & Science
Christopher Topalian

NOR
from ctypes import* AB
0 0=1
A=0 0 1=0
1 0=0

COLLEGEOFSCRIPTING.WEEBLY.COM
B=0 1 1=0
if (A == 0 and B == 0):
print('Both False')
windll.user32.MessageBoxW(0,
'Both False', 'NOR Gate', 0)
input('Press Enter to Exit')

Activates Only if
Both False
College of Scripting Music & Science
Christopher Topalian

XOR
from ctypes import* AB
0 0=0
A=1 0 1=1
B=0 1 0=1

COLLEGEOFSCRIPTING.WEEBLY.COM
1 1=0
if ((A == 0 and B == 1) or
(A == 1 and B == 0)):
print('A True or B True')
windll.user32.MessageBoxW(0,
'A True or B True', 'XOR Gate', 0)
input('Press Enter to Exit')

Activates Only if
A True or B True
College of Scripting Music & Science
Christopher Topalian

XNOR
A B
from ctypes import* 0 0=1
A=0 0 1=0
1 0=0

COLLEGEOFSCRIPTING.WEEBLY.COM
B=0 1 1=1
if ((A == 0 and B == 0) or
(A == 1 and B == 1)):
print('Both False or Both True')
windll.user32.MessageBoxW(0,
'Both False or Both True', 'XNOR Gate', 0)
input('Press Enter to Exit')

Activates Only if
Both False or
Both True
College of Scripting Music & Science
Christopher Topalian

CONVERSE IMPLICATION
A B
0 0=1
from ctypes import* 0 1=0
A=0 1 0=1

COLLEGEOFSCRIPTING.WEEBLY.COM
B=0 1 1=1
if (A == 1 or B == 0):
print('Both False or A True or Both True')
windll.user32.MessageBoxW(0,
'Both False or A True or Both True', 'Ci Gate', 0)
input('Press Enter to Exit')

Activates Only if
Both False or A
True or Both True
College of Scripting Music & Science
Christopher Topalian

CONVERSE NON IMPLICATION


from ctypes import* AB
0 0=0
A=0 0 1=1
1 0=0

COLLEGEOFSCRIPTING.WEEBLY.COM
B=1 1 1=0
if (A == 0 and B == 1):
print('B True')
windll.user32.MessageBoxW(0,
'B True', 'CNi Gate', 0)
input('Press Enter to Exit')

Activates Only if
B True
College of Scripting Music & Science
Christopher Topalian

MATERIAL IMPLICATION
A B
from ctypes import* 0 0=1
0 1=1
A=0 1 0=0

COLLEGEOFSCRIPTING.WEEBLY.COM
B=0 1 1=1
if (A == 0 or B == 1):
print('Both False or B True or Both True')
windll.user32.MessageBoxW(0,
'Both False or B True or Both True', 'Mi Gate', 0)
input('Press Enter to Exit')

Activates Only if
Both False or B
True or Both True
College of Scripting Music & Science
Christopher Topalian

MATERIAL NON IMPLICATION


from ctypes import* AB
0 0=0
A=1 0 1=0
1 0=1

COLLEGEOFSCRIPTING.WEEBLY.COM
B=0 1 1=0
if (A == 1 and B == 0):
print('A True')
windll.user32.MessageBoxW(0,
'A True', 'MNi Gate', 0)
input('Press Enter to Exit')

Activates Only if
A True
College of Scripting Music & Science
Christopher Topalian

Right Projection
from ctypes import* AB
0 0=0
A=1 0 1=1
1 0=0

COLLEGEOFSCRIPTING.WEEBLY.COM
B=1 1 1=1
if (B == 1):
print('B True or Both True')
windll.user32.MessageBoxW(0,
'B True or Both True', 'RP Gate', 0)
input('Press Enter to Exit')

Activates Only if
B True or
Both True
College of Scripting Music & Science
Christopher Topalian

Right Complementation
from ctypes import* AB
0 0=1
A=0 0 1=0
1 0=1

COLLEGEOFSCRIPTING.WEEBLY.COM
B=0 1 1=0
if (B == 0):
print('Both False or A True')
windll.user32.MessageBoxW(0,
'Both False or A True', 'RC Gate', 0)
input('Press Enter to Exit')

Activates Only if
Both False or
A True
College of Scripting Music & Science
Christopher Topalian

Left Projection
from ctypes import* AB
0 0=0
A=1 0 1=0
1 0=1

COLLEGEOFSCRIPTING.WEEBLY.COM
B=0 1 1=1
if (A == 1):
print('A True or Both True')
windll.user32.MessageBoxW(0,
'A True or Both True', 'LP Gate', 0)
input('Press Enter to Exit')

Activates Only if
A True or
Both True
College of Scripting Music & Science
Christopher Topalian

Left Complementation
AB
from ctypes import* 0 0=1
A=0 0 1=1
1 0=0

COLLEGEOFSCRIPTING.WEEBLY.COM
B=0 1 1=0
if (A == 0):
print('Both False or B True')
windll.user32.MessageBoxW(0,
'Both False or B True', 'LC Gate', 0)
input('Press Enter to Exit')

Activates Only if
Both False
or B True
College of Scripting Music & Science
Christopher Topalian

CONTRADICTION
from ctypes import* A B
0 0=0
A=0 0 1=0
B=0 1 0=0

COLLEGEOFSCRIPTING.WEEBLY.COM
if ((A == 0 or B == 0) or 1 1=0
(A == 1 or B == 1)):
print('One or Both False or True')
windll.user32.MessageBoxW(0,
'One or Both False or True',
'Contradiction Gate', 0)
input('Press Enter to Exit')

Activates Neg Text if


One or Both False
or True
College of Scripting Music & Science
Christopher Topalian

TAUTOLOGY
from ctypes import* A B
A=0 0 0=1
0 1=1
B=0 1 0=1

COLLEGEOFSCRIPTING.WEEBLY.COM
if ((A == 0 or B == 0) or 1 1=1
(A == 1 or B == 1)):
print('One or Both False or True')
windll.user32.MessageBoxW(0,
'One or Both False or True',
'Tautology Gate', 0)
input('Press Enter to Exit')

Activates if
One or Both False
or True
College of Scripting Music & Science
Christopher Topalian

True

COLLEGEOFSCRIPTING.WEEBLY.COM
AI
by
Christopher Topalian
Copyright 2000-2022
All Rights Reserved

College of Scripting Music & Science


Christopher Topalian

True Artificial Intelligence System


Tautology 16-Gon
MI 1111 CI
1101 1011
AND XNOR

COLLEGEOFSCRIPTING.WEEBLY.COM
0001 1001

LP RP
0011 0101

OR NOR
0111 1000

RC LC
1010 1100

XOR NAND
0110 1110
CNI MNI
0100 Contra- 0010
-diction
0000

College of Scripting Music & Science


Christopher Topalian

True Artificial Intelligence System


Tautology 16-Gon
MI 1111 CI
1101 1011
AND XNOR

COLLEGEOFSCRIPTING.WEEBLY.COM
0001 1001

LP RP
0011 0101

OR NOR
0111 1000

RC LC
1010 1100

XOR NAND
0110 1110
CNI MNI
0100 Contra- 0010
-diction
0000

College of Scripting Music & Science


Christopher Topalian

True Artificial Intelligence System


Tautology 16-Gon
MI 1111 CI
1101 1011
AND XNOR

COLLEGEOFSCRIPTING.WEEBLY.COM
0001 1001

LP RP
0011 0101

OR NOR
0111 1000

RC LC
1010 1100

XOR NAND
0110 1110
CNI MNI
0100 Contra- 0010
-diction
0000

College of Scripting Music & Science


Christopher Topalian

True Artificial Intelligence System


Tautology 16-Gon
MI 1111 CI
1101 1011
AND XNOR

COLLEGEOFSCRIPTING.WEEBLY.COM
0001 1001

LP RP
0011 0101

OR NOR
0111 1000

RC LC
1010 1100

XOR NAND
0110 1110
CNI MNI
0100 Contra- 0010
-diction
0000

College of Scripting Music & Science


Christopher Topalian

True Artificial Intelligence System


Tautology 16-Gon
MI 1111 CI
1101 1011
AND XNOR

COLLEGEOFSCRIPTING.WEEBLY.COM
0001 1001

LP RP
0011 0101

OR NOR
0111 1000

RC LC
1010 1100

XOR NAND
0110 1110
CNI MNI
0100 Contra- 0010
-diction
0000

College of Scripting Music & Science


Christopher Topalian

True Artificial Intelligence System


Tautology 16-Gon
MI 1111 CI
1101 1011
AND XNOR

COLLEGEOFSCRIPTING.WEEBLY.COM
0001 1001

LP RP
0011 0101

OR NOR
0111 1000

RC LC
1010 1100

XOR NAND
0110 1110
CNI MNI
0100 Contra- 0010
-diction
0000

College of Scripting Music & Science


Christopher Topalian

True Artificial Intelligence System


Tautology 16-Gon
MI 1111 CI
1101 1011
AND XNOR

COLLEGEOFSCRIPTING.WEEBLY.COM
0001 1001

LP RP
0011 0101

OR NOR
0111 1000

RC LC
1010 1100

XOR NAND
0110 1110
CNI MNI
0100 Contra- 0010
-diction
0000

College of Scripting Music & Science


Christopher Topalian

True Artificial Intelligence System


Tautology 16-Gon
MI 1111 CI
1101 1011
AND XNOR

COLLEGEOFSCRIPTING.WEEBLY.COM
0001 1001

LP RP
0011 0101

OR NOR
0111 1000

RC LC
1010 1100

XOR NAND
0110 1110
CNI MNI
0100 Contra- 0010
-diction
0000

College of Scripting Music & Science


Christopher Topalian
1111

Tautology
MI CI
1111

COLLEGEOFSCRIPTING.WEEBLY.COM
AND 1101 1011
XNOR
0001 1001
0111 LP RP 1000
0011 0101

OR NOR
0111 1000
RC LC
1010 1100
XOR NAND
0110 CNI MNI 1110
Contra-
0100 -diction 0010
0000
0000

College of Scripting Music & Science


Christopher Topalian
0001 1001

Tautology
MI CI
1111

COLLEGEOFSCRIPTING.WEEBLY.COM
1101 1011
AND XNOR
0001 1001
LP RP
0011 0101

OR NOR
0111 1000

RC LC
1010 1100

XOR NAND
0110 1110
0110 CNI Contra- MNI 1110
0100 -diction 0010
0000

College of Scripting Music & Science


Christopher Topalian

0011 0101

Tautology
MI CI

COLLEGEOFSCRIPTING.WEEBLY.COM
1101 1111 1011
AND XNOR
0001 1001
LP RP
0011 0101

OR NOR
0111 1000

RC LC
1010 1010 1100 1100
XOR NAND
0110 1110
CNI Contra- MNI
0100 -diction 0010
0000

College of Scripting Music & Science


Christopher Topalian

Tautology
MI CI
1111
1101 1011

COLLEGEOFSCRIPTING.WEEBLY.COM
AND XNOR
0001 1001
LP RP
0011 0101

OR NOR
0111 1000

RC LC
1010 1100

XOR NAND
0110 1110
CNI Contra- MNI
0100 -diction 0010
0000

College of Scripting Music & Science


Christopher Topalian
0001 1110 1101 0010

0110 1001 1011 0100

COLLEGEOFSCRIPTING.WEEBLY.COM
0111 1000 0011 1100

0000 1111 0101 1010

College of Scripting Music & Science


Christopher Topalian

True Artificial Intelligence System


Tautology 16-Gon
MI 1111 CI
1101 1011
AND XNOR

COLLEGEOFSCRIPTING.WEEBLY.COM
0001 1001

LP RP
0011 0101

OR NOR
0111 1000

RC LC
1010 1100

XOR NAND
0110 1110
CNI MNI
0100 Contra- 0010
-diction
0000

College of Scripting Music & Science


Christopher Topalian

True Artificial Intelligence System


Tautology 16-Gon
MI 1111 CI
1101 1011
AND XNOR

COLLEGEOFSCRIPTING.WEEBLY.COM
0001 1001

LP RP
0011 0101

OR NOR
0111 1000

RC LC
1010 1100

XOR NAND
0110 1110
CNI MNI
0100 Contra- 0010
-diction
0000

College of Scripting Music & Science


Christopher Topalian

True Artificial Intelligence System


Tautology 16-Gon
MI 1111 CI
1101 1011
AND XNOR

COLLEGEOFSCRIPTING.WEEBLY.COM
0001 1001

LP RP
0011 0101

OR NOR
0111 1000

RC LC
1010 1100

XOR NAND
0110 1110
CNI MNI
0100 Contra- 0010
-diction
0000

College of Scripting Music & Science


Christopher Topalian

True Artificial Intelligence System


Tautology 16-Gon
MI 1111 CI
1101 1011
AND XNOR

COLLEGEOFSCRIPTING.WEEBLY.COM
0001 1001

LP RP
0011 0101

OR NOR
0111 1000

RC LC
1010 1100

XOR NAND
0110 1110
CNI MNI
0100 Contra- 0010
-diction
0000

College of Scripting Music & Science


Christopher Topalian

True Artificial Intelligence System


Tautology 16-Gon
MI 1111 CI
1101 1011
AND XNOR

COLLEGEOFSCRIPTING.WEEBLY.COM
0001 1001

LP RP
0011 0101

OR NOR
0111 1000

RC LC
1010 1100

XOR NAND
0110 1110
CNI MNI
0100 Contra- 0010
-diction
0000

College of Scripting Music & Science


Christopher Topalian

True Artificial Intelligence System


Tautology 16-Gon
MI 1111 CI
1101 1011
AND XNOR

COLLEGEOFSCRIPTING.WEEBLY.COM
0001 1001

LP RP
0011 0101

OR NOR
0111 1000

RC LC
1010 1100

XOR NAND
0110 1110
CNI MNI
0100 Contra- 0010
-diction
0000

College of Scripting Music & Science


Christopher Topalian

True Artificial Intelligence System


Tautology 16-Gon
MI 1111 CI
1101 1011
AND XNOR

COLLEGEOFSCRIPTING.WEEBLY.COM
0001 1001

LP RP
0011 0101

OR NOR
0111 1000

RC LC
1010 1100

XOR NAND
0110 1110
CNI MNI
0100 Contra- 0010
-diction
0000

College of Scripting Music & Science


Christopher Topalian

COLLEGEOFSCRIPTING.WEEBLY.COM
Reference

College of Scripting Music & Science


Christopher Topalian

Updating Pip

COLLEGEOFSCRIPTING.WEEBLY.COM
python -m pip install --upgrade pip

We make sure to keep the pip up


to date with the latest version.

We open our Command Prompt


and type in:

python -m pip install --upgrade pip

College of Scripting Music & Science


Christopher Topalian

MessageBox

COLLEGEOFSCRIPTING.WEEBLY.COM
user32
options

College of Scripting Music & Science


Christopher Topalian
Alert sound
Greeting App X

X Hi Everyone ctypes.windll.user32.
MessageBoxW(0,
OK
ourText, ourTitle, 16)
Greeting App X

COLLEGEOFSCRIPTING.WEEBLY.COM
ctypes.windll.user32.
X Hi Everyone MessageBoxW(0,
OK Cancel
ourText, ourTitle, 17)

Greeting App X
ctypes.windll.user32.
X Hi Everyone MessageBoxW(0,
ourText, ourTitle, 18)
Abort Retry Ignore

Greeting App X ctypes.windll.user32.


X Hi Everyone MessageBoxW(0,
ourText, ourTitle, 19)
Yes No Cancel
College of Scripting Music & Science
Christopher Topalian

Greeting App X
ctypes.windll.user32.
X Hi Everyone MessageBoxW(0,
ourText, ourTitle, 20)
Yes No

COLLEGEOFSCRIPTING.WEEBLY.COM
Greeting App X
ctypes.windll.user32.
X Hi Everyone MessageBoxW(0,
ourText, ourTitle, 21)
Retry Cancel

Greeting App X
ctypes.windll.user32.
X Hi Everyone MessageBoxW(0,
ourText, ourTitle, 22)
Cancel Try Again Continue

College of Scripting Music & Science


X Christopher Topalian
Alert sound
Greeting App

Hi Everyone ctypes.windll.user32.
! MessageBoxW(0,
OK ourText, ourTitle, 48)
Greeting App X

COLLEGEOFSCRIPTING.WEEBLY.COM
ctypes.windll.user32.
! Hi Everyone MessageBoxW(0,
OK Cancel
ourText, ourTitle, 49)

Greeting App X
ctypes.windll.user32.
! Hi Everyone MessageBoxW(0,
Abort Retry Ignore
ourText, ourTitle, 50)

Greeting App X
ctypes.windll.user32.
! Hi Everyone MessageBoxW(0,
ourText, ourTitle, 51)
Yes No Cancel
College of Scripting Music & Science
Christopher Topalian

Greeting App X
ctypes.windll.user32.
! Hi Everyone MessageBoxW(0,
ourText, ourTitle, 52)
Yes No

COLLEGEOFSCRIPTING.WEEBLY.COM
Greeting App X
ctypes.windll.user32.
! Hi Everyone MessageBoxW(0,
ourText, ourTitle, 53)
Retry Cancel

Greeting App X
ctypes.windll.user32.
! Hi Everyone MessageBoxW(0,
ourText, ourTitle, 54)
Cancel Try Again Continue

College of Scripting Music & Science


X Christopher Topalian
Alert sound
Greeting App

i Hi Everyone ctypes.windll.user32.
MessageBoxW(0,
OK ourText, ourTitle, 64)
Greeting App X

COLLEGEOFSCRIPTING.WEEBLY.COM
ctypes.windll.user32.
i Hi Everyone MessageBoxW(0,
OK Cancel
ourText, ourTitle, 65)

Greeting App X
ctypes.windll.user32.
i Hi Everyone MessageBoxW(0,
ourText, ourTitle, 66)
Abort Retry Ignore

Greeting App X ctypes.windll.user32.


i Hi Everyone MessageBoxW(0,
ourText, ourTitle, 67)
Yes No Cancel
College of Scripting Music & Science
Christopher Topalian

Greeting App X
ctypes.windll.user32.
i Hi Everyone MessageBoxW(0,
ourText, ourTitle, 68)
Yes No

COLLEGEOFSCRIPTING.WEEBLY.COM
Greeting App X
ctypes.windll.user32.
i Hi Everyone MessageBoxW(0,
ourText, ourTitle, 69)
Retry Cancel

Greeting App X
ctypes.windll.user32.
i Hi Everyone MessageBoxW(0,
ourText, ourTitle, 70)
Cancel Try Again Continue

College of Scripting Music & Science


X Christopher Topalian
Alert sound
Greeting App

Hi Everyone ctypes.windll.user32.
MessageBoxW(0,
OK
ourText, ourTitle, 80)
Greeting App X

COLLEGEOFSCRIPTING.WEEBLY.COM
ctypes.windll.user32.
Hi Everyone
MessageBoxW(0,
OK Cancel
ourText, ourTitle, 81)

Greeting App X
ctypes.windll.user32.
Hi Everyone MessageBoxW(0,
Abort Retry Ignore
ourText, ourTitle, 82)

Greeting App X ctypes.windll.user32.


Hi Everyone MessageBoxW(0,
ourText, ourTitle, 83)
Yes No Cancel
College of Scripting Music & Science
Christopher Topalian

Greeting App X
ctypes.windll.user32.
Hi Everyone MessageBoxW(0,
ourText, ourTitle, 84)
Yes No

COLLEGEOFSCRIPTING.WEEBLY.COM
Greeting App X
ctypes.windll.user32.
Hi Everyone MessageBoxW(0,
ourText, ourTitle, 85)
Retry Cancel

Greeting App X
ctypes.windll.user32.
Hi Everyone MessageBoxW(0,
ourText, ourTitle, 86)
Cancel Try Again Continue

College of Scripting Music & Science


X Christopher
No Topalian
alert sound
Greeting App

Hi Everyone ctypes.windll.user32.
MessageBoxW(0,
OK ourText, ourTitle, 256)
Greeting App X
ctypes.windll.user32.

COLLEGEOFSCRIPTING.WEEBLY.COM
Hi Everyone MessageBoxW(0,
ourText, ourTitle, 257)
OK Cancel

Greeting App X
ctypes.windll.user32.
Hi Everyone MessageBoxW(0,
Abort Retry Ignore
ourText, ourTitle, 258)

Greeting App X ctypes.windll.user32.


Hi Everyone MessageBoxW(0,
ourText, ourTitle, 259)
Yes No Cancel
College of Scripting Music & Science
Christopher Topalian

Greeting App X
ctypes.windll.user32.
Hi Everyone MessageBoxW(0,
ourText, ourTitle, 260)
Yes No

COLLEGEOFSCRIPTING.WEEBLY.COM
Greeting App X
ctypes.windll.user32.
Hi Everyone MessageBoxW(0,
ourText, ourTitle, 261)
Retry Cancel

Greeting App X
ctypes.windll.user32.
Hi Everyone MessageBoxW(0,
ourText, ourTitle, 262)
Cancel Try Again Continue

College of Scripting Music & Science


X Christopher Topalian
Alert sound
Greeting App

X Hi Everyone ctypes.windll.user32.
MessageBoxW(0,
OK ourText, ourTitle, 272)
Greeting App X

COLLEGEOFSCRIPTING.WEEBLY.COM
ctypes.windll.user32.
X Hi Everyone MessageBoxW(0,
OK Cancel
ourText, ourTitle, 273)

Greeting App X
ctypes.windll.user32.
X Hi Everyone MessageBoxW(0,
Abort Retry Ignore
ourText, ourTitle, 274)

Greeting App X ctypes.windll.user32.


X Hi Everyone MessageBoxW(0,
ourText, ourTitle, 275)
Yes No Cancel
College of Scripting Music & Science
Christopher Topalian

Greeting App X
ctypes.windll.user32.
X Hi Everyone MessageBoxW(0,
ourText, ourTitle, 276)
Yes No

COLLEGEOFSCRIPTING.WEEBLY.COM
Greeting App X
ctypes.windll.user32.
X Hi Everyone MessageBoxW(0,
ourText, ourTitle, 277)
Retry Cancel

Greeting App X
ctypes.windll.user32.
X Hi Everyone MessageBoxW(0,
ourText, ourTitle, 278)
Cancel Try Again Continue

College of Scripting Music & Science


X Christopher
No Topalian
Alert sound
Greeting App

i Hi Everyone ctypes.windll.user32.
MessageBoxW(0,
OK ourText, ourTitle, 288)
Greeting App X
ctypes.windll.user32.

COLLEGEOFSCRIPTING.WEEBLY.COM
i Hi Everyone MessageBoxW(0,
ourText, ourTitle, 289)
OK Cancel

Greeting App X
ctypes.windll.user32.
i Hi Everyone MessageBoxW(0,
ourText, ourTitle, 290)
Abort Retry Ignore

X
Greeting App ctypes.windll.user32.
i Hi Everyone MessageBoxW(0,
ourText, ourTitle, 291)
Yes No Cancel
College of Scripting Music & Science
Christopher Topalian

Greeting App X
ctypes.windll.user32.
i Hi Everyone MessageBoxW(0,
Yes No
ourText, ourTitle, 292)

COLLEGEOFSCRIPTING.WEEBLY.COM
Greeting App X
ctypes.windll.user32.
i Hi Everyone MessageBoxW(0,
ourText, ourTitle, 293)
Retry Cancel

Greeting App X
ctypes.windll.user32.
i Hi Everyone MessageBoxW(0,
ourText, ourTitle, 294)
Cancel Try Again Continue

College of Scripting Music & Science


X Christopher Topalian
Alert sound
Greeting App

Hi Everyone ctypes.windll.user32.
! MessageBoxW(0,
OK ourText, ourTitle, 304)
Greeting App X

COLLEGEOFSCRIPTING.WEEBLY.COM
ctypes.windll.user32.
! Hi Everyone MessageBoxW(0,
OK Cancel
ourText, ourTitle, 305)

Greeting App X
ctypes.windll.user32.
! Hi Everyone MessageBoxW(0,
ourText, ourTitle, 306)
Abort Retry Ignore

X
Greeting App ctypes.windll.user32.
Hi Everyone MessageBoxW(0,
!
ourText, ourTitle, 307)
Yes No Cancel
College of Scripting Music & Science
Christopher Topalian

Greeting App X
ctypes.windll.user32.
! Hi Everyone MessageBoxW(0,
Yes No
ourText, ourTitle, 308)

COLLEGEOFSCRIPTING.WEEBLY.COM
Greeting App X
ctypes.windll.user32.
! Hi Everyone MessageBoxW(0,
ourText, ourTitle, 309)
Retry Cancel

Greeting App X
ctypes.windll.user32.
! Hi Everyone MessageBoxW(0,
ourText, ourTitle, 310)
Cancel Try Again Continue

College of Scripting Music & Science


X Christopher Topalian
Alert sound
Greeting App

i Hi Everyone ctypes.windll.user32.
MessageBoxW(0,
OK ourText, ourTitle, 320)
Greeting App X

COLLEGEOFSCRIPTING.WEEBLY.COM
ctypes.windll.user32.
i Hi Everyone MessageBoxW(0,
OK Cancel
ourText, ourTitle, 321)

Greeting App X
ctypes.windll.user32.
i Hi Everyone MessageBoxW(0,
ourText, ourTitle, 322)
Abort Retry Ignore

X
Greeting App ctypes.windll.user32.
i Hi Everyone MessageBoxW(0,
ourText, ourTitle, 323)
Yes No Cancel
College of Scripting Music & Science
Christopher Topalian

Greeting App X
ctypes.windll.user32.
i Hi Everyone MessageBoxW(0,
Yes No
ourText, ourTitle, 324)

COLLEGEOFSCRIPTING.WEEBLY.COM
Greeting App X
ctypes.windll.user32.
i Hi Everyone MessageBoxW(0,
ourText, ourTitle, 325)
Retry Cancel

Greeting App X
ctypes.windll.user32.
i Hi Everyone MessageBoxW(0,
ourText, ourTitle, 326)
Cancel Try Again Continue

College of Scripting Music & Science


X Christopher Topalian
Alert sound
Greeting App

Hi Everyone ctypes.windll.user32.
MessageBoxW(0,
OK ourText, ourTitle, 336)
Greeting App X

COLLEGEOFSCRIPTING.WEEBLY.COM
ctypes.windll.user32.
Hi Everyone MessageBoxW(0,
OK Cancel
ourText, ourTitle, 337)

Greeting App X
ctypes.windll.user32.
Hi Everyone MessageBoxW(0,
Abort Retry Ignore
ourText, ourTitle, 338)

Greeting App X ctypes.windll.user32.


Hi Everyone MessageBoxW(0,
ourText, ourTitle, 339)
Yes No Cancel
College of Scripting Music & Science
Christopher Topalian

Greeting App X
ctypes.windll.user32.
Hi Everyone MessageBoxW(0,
Yes No
ourText, ourTitle, 340)

COLLEGEOFSCRIPTING.WEEBLY.COM
Greeting App X
ctypes.windll.user32.
Hi Everyone MessageBoxW(0,
ourText, ourTitle, 341)
Retry Cancel

Greeting App X
ctypes.windll.user32.
Hi Everyone MessageBoxW(0,
ourText, ourTitle, 342)
Cancel Try Again Continue

College of Scripting Music & Science


Christopher Topalian

MessageBox

COLLEGEOFSCRIPTING.WEEBLY.COM
tkinter
options
College of Scripting Music & Science
Christopher Topalian
Simple Message Box
import tkinter
from tkinter import messagebox
ourWindow = tkinter.Tk()
ourWindow.geometry("50x50")

COLLEGEOFSCRIPTING.WEEBLY.COM
ourTitle = "Greeting App"
ourMessage = "Hi Everyone"
ourText = messagebox.showinfo(ourMessage,
ourMessage)
Greeting App X
ourWindow.mainloop()
i Hi Everyone

OK

The messagebox appears, with an info icon


and shows ourTitle, which is "Greeting App"
and ourMessage, which is "Hi Everyone".
College of Scripting Music & Science
Christopher Topalian
Open a Message Box, Yes No
import tkinter
from tkinter import messagebox
ourWindow = tkinter.Tk()
ourWindow.geometry("50x50")

COLLEGEOFSCRIPTING.WEEBLY.COM
ourTitle = "Our Question"
ourMessage = "Is Melissa Here?"
ourText = messagebox.askyesno(ourMessage,
ourMessage)
#print(ourText) Our Question X
if(ourText == True): Is Melissa Here?
print("Pressed Yes")
if(ourText == False): Yes No
print("Pressed No")
True False
ourWindow.mainloop()

askyesno returns True or False


College of Scripting Music & Science
Christopher Topalian
Open a Message Box, OK, Cancel
import tkinter
from tkinter import messagebox
ourWindow = tkinter.Tk()
ourWindow.geometry("50x50")

COLLEGEOFSCRIPTING.WEEBLY.COM
ourText = messagebox.askquestion("Question",
"Are You Ready?")
#print(ourText)
Question X
if(ourText == 'yes'):
print("Pressed Yes") Are You Ready?

if(ourText == 'no'): Yes No


print("Pressed No")
yes no
ourWindow.mainloop()

askquestion returns yes or no.


College of Scripting Music & Science
Christopher Topalian
Open a Message Box, OK, Cancel
import tkinter
from tkinter import messagebox
ourWindow = tkinter.Tk()
ourWindow.geometry("50x50")

COLLEGEOFSCRIPTING.WEEBLY.COM
ourTitle = "Our Question"
ourMessage = "Ready?"
ourText = messagebox.askokcancel(ourMessage,
ourMessage)
#print(ourText) Our Question X
if(ourText == True): Ready?
print("Pressed OK")
if(ourText == False): OK Cancel
print("Pressed Cancel")
True False
ourWindow.mainloop()

askokcancel returns True or False.


College of Scripting Music & Science
Christopher Topalian
Open a Message Box, OK, Cancel
import tkinter
from tkinter import messagebox
ourWindow = tkinter.Tk()
ourWindow.geometry("50x50")

COLLEGEOFSCRIPTING.WEEBLY.COM
ourTitle = "Our Question"
ourMessage = "Ready?"
ourText = messagebox.askretrycancel(ourMessage,
ourMessage)
#print(ourText) Our Question X
if(ourText == True):
Ready?
print("Pressed Retry")
if(ourText == False): Retry Cancel
print("Pressed Cancel")
ourWindow.mainloop() True False

askokcancel returns True or False.


College of Scripting Music & Science
Christopher Topalian
Open a Message Box
import tkinter
from tkinter import messagebox
ourWindow = tkinter.Tk()
ourWindow.geometry("50x50")

COLLEGEOFSCRIPTING.WEEBLY.COM
ourTitle = "Our Question"
ourMessage = "Ready"
ourText = messagebox.askyesnocancel(ourMessage,
ourMessage)
#print(ourText)
if(ourText == True): Our Question X
print("Pressed Yes")
Ready?
if(ourText == False):
print("Pressed No")
Yes No Cancel
if(ourText == None):
print("Pressed Cancel") yes no cancel
ourWindow.mainloop()
askyesnocancel returns True, False or None.
College of Scripting Music & Science
Christopher Topalian
Open a Message Box
import tkinter
from tkinter import messagebox
ourWindow = tkinter.Tk()
ourWindow.geometry("50x50")

COLLEGEOFSCRIPTING.WEEBLY.COM
ourTitle = "Warning Message"
ourMessage = "Careful!"

ourText = messagebox.showwarning(ourMessage,
ourMessage)
Warning Message X
ourWindow.mainloop()
Careful!
!
OK

showwarning shows a warning symbol,


showinfo shows an info symbol, and
showerror show an error message.
College of Scripting Music & Science
Christopher Topalian

COLLEGEOFSCRIPTING.WEEBLY.COM
List

College of Scripting Music & Science


Christopher Topalian

show all items, one line

ourList = [ 1, 2, 3, 4, 5 ]

COLLEGEOFSCRIPTING.WEEBLY.COM
print(*ourList)

input("Press Enter to Exit")

output:
12345
Show All
Items in a List
College of Scripting Music & Science
Christopher Topalian

show all items, comma separator

ourList = [ 1, 2, 3, 4, 5 ]

COLLEGEOFSCRIPTING.WEEBLY.COM
print(*ourList, sep=", ")

input("Press Enter to Exit")

output:
1, 2, 3, 4, 5
Show All
Items in a List
College of Scripting Music & Science
Christopher Topalian

show all items, new line separator

ourList = [ 1, 2, 3, 4, 5 ]

COLLEGEOFSCRIPTING.WEEBLY.COM
print(*ourList, sep="\n")

input("Press Enter to Exit")


output:
1
2
3 Show All
4 Items in a List
5
College of Scripting Music & Science
Christopher Topalian

for loop, show all items

ourList = [ 1, 2, 3, 4, 5 ]
for x in ourList:

COLLEGEOFSCRIPTING.WEEBLY.COM
print(x)
input("Press Enter to Exit")
output:
1
2
3 Show All
4 Items in a List
5
College of Scripting Music & Science
Christopher Topalian

for loop, show all items, range, len

ourList = [ 1, 2, 3, 4, 5 ]
for x in range(len(ourList)):

COLLEGEOFSCRIPTING.WEEBLY.COM
print(ourList[x])
input("Press Enter to Exit")
output:
1
2
3 Show All
4 Items in a List
5
College of Scripting Music & Science
Christopher Topalian
while, if, break
ourList = [1, 2, 3, 4, 5 ]

x=0

COLLEGEOFSCRIPTING.WEEBLY.COM
while x < len(ourList):
print(ourList[x])
x += 1
if x == 2:
print("Loop Stopped")
break
output: Stops at 2,
1
2
because
Loop Stopped of the break
College of Scripting Music & Science
Christopher Topalian

while, continue, break, if, elif, else


ourList = [1, 2, 3, 4, 5 ]
x=0
while x < len(ourList):

COLLEGEOFSCRIPTING.WEEBLY.COM
print(ourList[x])
x += 1
if x == 2:
question = input("Continue? Y or N \n")
if(question == "y"):
continue output:
elif(question == "n"): 1
print("Exiting") 2
break Continue? Y or N
y
else: 3
print("Exiting") 4
break 5
College of Scripting Music & Science
Christopher Topalian

for, if, break


ourList = [1,2,3,4,5,6,7,8,9,10];
q1 = "defaultValue"
for x in ourList:

COLLEGEOFSCRIPTING.WEEBLY.COM
print(x)
if(x == 5):
q1 = input("Continue? Y or N \n")
if(q1 == "y"):
continue
if(q1 == "n"): output:
print("Exiting loop") 1
2
break 3
4
5
Continue? Y or N
n
Exiting Loop
College of Scripting Music & Science
Christopher Topalian

random integer from 0 to 10


import random
ourNumber = random.randint(0,10)

COLLEGEOFSCRIPTING.WEEBLY.COM
print(ourNumber)

input("Press Enter to Exit")

Each time you run the script,


it will show a random number.
output: output: Show a
10 3
Random
output: output:
7 4
Number
College of Scripting Music & Science
Christopher Topalian
class with function
class Pokemon:
def __init__(self, name, kind):
self.name = name
self.kind = kind

COLLEGEOFSCRIPTING.WEEBLY.COM
def showInfo(self):
print("Name " + self.name + "\n" + "Kind "
+ self.kind)

pikachu = Pokemon("Pikachu", "Electric")

pikachu.showInfo()

_ _init_ _ output:
Name Pikachu
Kind Electric
Underscores
College of Scripting Music & Science
Christopher Topalian
class with function and line breaks
class Pokemon:
def __init__(self, name, kind):
self.name = name
self.kind = kind

COLLEGEOFSCRIPTING.WEEBLY.COM
def showInfo(self):
print("Name " + self.name + "\n" + "Kind "
+ self.kind)

pikachu = Pokemon(
"Pikachu", #name
"Electric" #kind
) output:
Name Pikachu
pikachu.showInfo() Kind Electric

We can use multiple lines for visual clarity


in constructing our object
College of Scripting Music & Science
Christopher Topalian
save as ourDateLibrary.py
from datetime import datetime
import time
def dateAndTime(repeat):
if(repeat == "true"):

COLLEGEOFSCRIPTING.WEEBLY.COM
while(repeat == "true"):
now = datetime.now()
theTime = now.strftime("%m/%d/%Y
%H:%M:%S")
print(theTime)
time.sleep(1)
else:
now = datetime.now()
once = now.strftime("%m/%d/%Y %H:
%M:%S")
print(once)
The next tutorial imports this script.
Make sure both scripts are in the same folder!
College of Scripting Music & Science
Christopher Topalian
We import script from previous page
from ourDateLibrary import*

dateAndTime("true")

COLLEGEOFSCRIPTING.WEEBLY.COM
This script imports the script from the
previous page named ourDateLibrary.py
Make sure both scripts are in the same folder!
If we write true, it keeps getting
date & time output:
dateAndTime("true") 03/30/2022 17:06:17
03/30/2022 17:06:18
If we write anything else, 03/30/2022 17:06:19
such as 03/30/2022 17:06:20
03/30/2022 17:06:21
dateAndTime("false")
it will only get the output:
date and time once. 03/30/2022 17:06:22
College of Scripting Music & Science
Christopher Topalian

How to Activate

COLLEGEOFSCRIPTING.WEEBLY.COM
a Nodejs script
with a
Python Script

College of Scripting Music & Science


Christopher Topalian

nodejs
Note: To use nodejs,
we must have nodejs

COLLEGEOFSCRIPTING.WEEBLY.COM
installed on our computer.
We make sure to first install
nodejs, before doing the
next tutorials.

https://nodejs.org/en/download/

College of Scripting Music & Science


Christopher Topalian

We install the Naked package


to be able to activate
nodejs scripts using python

COLLEGEOFSCRIPTING.WEEBLY.COM
pip install Naked

We will then be able to double click


on our python script named runIt.pyw
to activate our nodejs script named simple.js

runIt.pyw simple.js test.txt


College of Scripting Music & Science
Christopher Topalian

We run this python script to activate


our nodejs script by name
from Naked.toolshed.shell import muterun_js

COLLEGEOFSCRIPTING.WEEBLY.COM
theResponse = muterun_js('simple.js')

We save this python script as runIt.pyw


so that when we double click on the script,
no console window will appear.
The next page shows the nodejs script
named simple.js that will be activated.
We make sure that the python script and
the nodejs script are in the same folder.

College of Scripting Music & Science


Christopher Topalian

We save this nodejs script as


simple.js
Make sure this nodejs script is in the same
folder as the python activator script.

COLLEGEOFSCRIPTING.WEEBLY.COM
const fs = require('fs')

let ourText = 'Hi Everyone'

fs.writeFile('test.txt', ourText, function(err)


{
if (err) {
console.error(err)
return nodejs
} script
console.log("Works good");
saved as
}) simple.js
College of Scripting Music & Science
Christopher Topalian

The Naked package makes it so


we can activate our nodejs scripts
by
double clicking on our

COLLEGEOFSCRIPTING.WEEBLY.COM
python script in the folder.
If we didn't use the
python Naked package,
to run our nodejs script,
we would have instead had to open
the command prompt
and then type
node nameOfOurScript.js
and then press Enter
College of Scripting Music & Science
Christopher Topalian
Gets the name of the nodejs file in the
folder and activates it
from Naked.toolshed.shell import muterun_js

import os

COLLEGEOFSCRIPTING.WEEBLY.COM
path =
os.path.dirname(os.path.realpath(__file__))

for folder, subfolder, ourFiles in os.walk(path):


for file in ourFiles:
if(file.endswith(".js")):
print(os.path.join(folder,file))
thePath = os.path.join(folder,file)
theResponse = muterun_js(thePath)

We save this script as runIt.pyw


so that no console window will appear.
College of Scripting Music & Science
Christopher Topalian

Now when we double click the


python script named runIt.pyw
it will activate the nodejs script
named simple.js

COLLEGEOFSCRIPTING.WEEBLY.COM
runIt.pyw simple.js test.txt

In this case, our nodejs script


makes a text file called test.txt
College of Scripting Music & Science
Christopher Topalian

start if
diagram

test
FALSE

COLLEGEOFSCRIPTING.WEEBLY.COM
TRUE

body

Exit
College of Scripting Music & Science
Christopher Topalian

if if
diagram
FALSE
name == "john"

COLLEGEOFSCRIPTING.WEEBLY.COM
TRUE

print("Hi " + name);

Exit
College of Scripting Music & Science
Christopher Topalian

do while
diagram
start

COLLEGEOFSCRIPTING.WEEBLY.COM
body
FALSE

Exit test
TRUE

College of Scripting Music & Science


Christopher Topalian

while
diagram
start

COLLEGEOFSCRIPTING.WEEBLY.COM
FALSE

Exit test
TRUE

body

College of Scripting Music & Science


Christopher Topalian

for
diagram
Start number

COLLEGEOFSCRIPTING.WEEBLY.COM
FALSE

Exit test
TRUE

body

increment++
College of Scripting Music & Science
Christopher Topalian

and
diagram
off

COLLEGEOFSCRIPTING.WEEBLY.COM
A B

on

A B

College of Scripting Music & Science


Christopher Topalian

or
diagram
A

COLLEGEOFSCRIPTING.WEEBLY.COM
off

A on

College of Scripting Music & Science


Christopher Topalian

and or
diagram

COLLEGEOFSCRIPTING.WEEBLY.COM
off

A B

on

A B

College of Scripting Music & Science


Christopher Topalian

Resources:
https://docs.python.org/3/

COLLEGEOFSCRIPTING.WEEBLY.COM
https://www.pygame.org/docs/

https://docs.opencv.org/master/d6/
d00/tutorial_py_root.html

https://collegeofscripting.weebly.com/

https://collegeofscripting.wordpress.com

Happy Programming!
College of Scripting Music & Science
Christopher Topalian

DEDICATED
TO
GOD THE FATHER
Presented by the

COLLEGEOFSCRIPTING.WEEBLY.COM
College of Scripting
Music & Science
We have taught over 2 million people
how to program computers, for free,
since March of 2007!
www.youtube.com/ScriptingCollege
www.github.com/ChristopherTopalian
www.CollegeOfScripting.weebly.com
www.CollegeOfScripting.wordpress.com
Christopher Topalian Copyright 2000-2022
All Rights Reserved. All content here is protected.
College of Scripting Music & Science

You might also like