Python Language For Humans by Christopher Topalian
Python Language For Humans by Christopher Topalian
PYTHON
LANGUAGE
COLLEGEOFSCRIPTING.WEEBLY.COM
For
Humans
by
Christopher Topalian
Copyright 2000-2022
All Rights Reserved
COLLEGEOFSCRIPTING.WEEBLY.COM
DEDICATED
TO
GOD THE FATHER
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
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/
COLLEGEOFSCRIPTING.WEEBLY.COM
COLLEGEOFSCRIPTING.WEEBLY.COM
Left Click
Download Python 3.9.1
Left Click
Save File
Save File Cancel
COLLEGEOFSCRIPTING.WEEBLY.COM
Double Left Click
python-3.9.1-amd64.exe
COLLEGEOFSCRIPTING.WEEBLY.COM
COLLEGEOFSCRIPTING.WEEBLY.COM
Install Now
C:\Users\energy\AppData\Local\Programs\Python\Python39
Check Marks
in Both Custom installation
Choose location and features
Check Boxes
COLLEGEOFSCRIPTING.WEEBLY.COM
Should I Disable path
length limit?
Left Click
Windows Button
COLLEGEOFSCRIPTING.WEEBLY.COM
Left Click
Python 3.9 Folder
Left Click
IDLE (Python 3.9)
COLLEGEOFSCRIPTING.WEEBLY.COM
We Can Type Code Here
and then press Enter
COLLEGEOFSCRIPTING.WEEBLY.COM
New File Ctrl+N
Left Click
New File
COLLEGEOFSCRIPTING.WEEBLY.COM
ourText = "Hi Everyone"
ctypes.windll.user32.MessageBoxW(0,
ourText, ourTitle, 0)
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
COLLEGEOFSCRIPTING.WEEBLY.COM
COLLEGEOFSCRIPTING.WEEBLY.COM
Name the File
ourFirstScript.py
COLLEGEOFSCRIPTING.WEEBLY.COM
Double
Left Click
To Open
Greeting Message X
COLLEGEOFSCRIPTING.WEEBLY.COM
i Hi Everyone
OK
COLLEGEOFSCRIPTING.WEEBLY.COM
Left Click
Run Module
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)
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)
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?
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,
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
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)
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)
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
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
COLLEGEOFSCRIPTING.WEEBLY.COM
Show Code Context Configure IDLE
Show Line Numbers
Zoom Height Alt + 2
Left Click
Font/Tabs
COLLEGEOFSCRIPTING.WEEBLY.COM
Left Click
Size
Left Click
18
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.
COLLEGEOFSCRIPTING.WEEBLY.COM
Greeting App X
Hi Everyone
OK
COLLEGEOFSCRIPTING.WEEBLY.COM
MATH
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
def ourFunction():
ourText = math.floor(4.45)
answer = str(ourText)
return answer
ctypes.windll.user32.MessageBoxW(0,
ourFunction(), ourTitle, 0)
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)
COLLEGEOFSCRIPTING.WEEBLY.COM
import ctypes
ctypes.windll.shcore.SetProcessDpiAwareness(1)
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)
64
OK
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
COLLEGEOFSCRIPTING.WEEBLY.COM
ourText = str(ourText) Convert to String
ctypes.windll.user32.MessageBoxW(0,
ourText, ourTitle, 0)
2.0
OK
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
COLLEGEOFSCRIPTING.WEEBLY.COM
answer = str(ourFunction(30,20))
result = ctypes.windll.user32.MessageBoxW(0,
answer,"Subtraction", 0)
Subtraction X
i 10
OK
COLLEGEOFSCRIPTING.WEEBLY.COM
answer = str(ourFunction(4,4))
result = ctypes.windll.user32.MessageBoxW(0,
answer,"Multiplication", 0)
Multiplication X
i 16
OK
COLLEGEOFSCRIPTING.WEEBLY.COM
answer = str(ourFunction(16,4))
result = ctypes.windll.user32.MessageBoxW(0,
answer,"Division", 0)
Division X
i 4.0
OK
MAKE AN
COLLEGEOFSCRIPTING.WEEBLY.COM
APP
WINDOW
COLLEGEOFSCRIPTING.WEEBLY.COM
ourWindow.geometry('500x300+300+200')
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()
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()
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()
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()
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()
COLLEGEOFSCRIPTING.WEEBLY.COM
Text Field
for
User Input
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()
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()
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
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
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
COLLEGEOFSCRIPTING.WEEBLY.COM
input('Press Enter to Exit')
IDLE Shell 3.9.1 X
File Edit Format Run Options Window Help
x=0
COLLEGEOFSCRIPTING.WEEBLY.COM
while x != 1:
time.sleep(4.0)
print('4 seconds passed')
COLLEGEOFSCRIPTING.WEEBLY.COM
time.sleep(4.0)
ctypes.windll.user32.MessageBoxW(0,
ourText, ourTitle, 0)
COLLEGEOFSCRIPTING.WEEBLY.COM
x=1
while x <= 5:
time.sleep(2.0)
x = x + 1;
ctypes.windll.user32.MessageBoxW(0,
ourText, ourTitle, 0)
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)
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
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
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
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
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
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
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
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
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
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
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
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
COLLEGEOFSCRIPTING.WEEBLY.COM
Creates a TXT file in the same
folder that ourScript.py is in
COLLEGEOFSCRIPTING.WEEBLY.COM
Both files are in
SAME Folder!
os.startfile('C:/Users/you/Desktop/testFile.txt')
COLLEGEOFSCRIPTING.WEEBLY.COM
testFile.txt
is located
on our
Desktop!
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.
COLLEGEOFSCRIPTING.WEEBLY.COM
multi line style.'
ourFile = open('testFile.txt', 'w')
ourFile.write(ourText)
ourFile.close() w a
writes/ appends
overwrites at end
COLLEGEOFSCRIPTING.WEEBLY.COM
ctypes.windll.user32.MessageBoxW(0,
x, "The Title", 0)
The Title X
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()
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))
COLLEGEOFSCRIPTING.WEEBLY.COM
for file in ourFiles:
if(file.endswith(".jpg")):
print(os.path.join(folder,file))
input('Press Enter to Exit')
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')
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
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')
Comments
COLLEGEOFSCRIPTING.WEEBLY.COM
Single Line
Multi Line
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.
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,
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
COLLEGEOFSCRIPTING.WEEBLY.COM
def ourFunction():
ourText = "Howdy" Local Variable
return ourText
return the Variable
ctypes.windll.user32.MessageBoxW(0,
ourFunction(), ourTitle, 0)
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)
Control + [
COLLEGEOFSCRIPTING.WEEBLY.COM
Tabs our code to the LEFT
Control + ]
Tabs our code to the RIGHT
College of Scripting Music & Science
Christopher Topalian
COLLEGEOFSCRIPTING.WEEBLY.COM
INTERNET
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')
COLLEGEOFSCRIPTING.WEEBLY.COM
List of
Dictionaries
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
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')
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')
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')
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')
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
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')
List of
COLLEGEOFSCRIPTING.WEEBLY.COM
Dictionaries
DELETE
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')
List of
COLLEGEOFSCRIPTING.WEEBLY.COM
Dictionaries
DELETE
Last Item
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')
List of
COLLEGEOFSCRIPTING.WEEBLY.COM
Dictionaries
EDIT by Key
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
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')
print(ourData.ourText)
College of Scripting Music & Science
Christopher Topalian
First Way of Importing ourData.py
COLLEGEOFSCRIPTING.WEEBLY.COM
import ourData ourText = 'Howdy'
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'
EXTERNAL
COLLEGEOFSCRIPTING.WEEBLY.COM
FILE
Example 2
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)
COLLEGEOFSCRIPTING.WEEBLY.COM
answer += str(z) + '\n\n'
Keeps Name
ctypes.windll.user32.MessageBoxW(0, Space Clean!
answer, "The Speakers", 0)
COLLEGEOFSCRIPTING.WEEBLY.COM
speakersUSA
answer += str(name) + '\n\n'
ctypes.windll.user32.MessageBoxW(0,
answer, "The Speakers", 0)
HOW TO
COLLEGEOFSCRIPTING.WEEBLY.COM
OPEN
COMMAND
PROMPT
Shortcut to Open
Command Prompt
Press Windows Key
COLLEGEOFSCRIPTING.WEEBLY.COM
Type CMD
Press Enter
Shortcut to Open
Command Prompt
Press Windows Key + R
COLLEGEOFSCRIPTING.WEEBLY.COM
Type CMD
Press Enter
COLLEGEOFSCRIPTING.WEEBLY.COM
We Type
the word
pip
pip to see
what
commands
it offers
Shows
Often
Used
Commands
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
How to Install
a Package
COLLEGEOFSCRIPTING.WEEBLY.COM
pip install 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
Install a
COLLEGEOFSCRIPTING.WEEBLY.COM
Package
Using Pip
COLLEGEOFSCRIPTING.WEEBLY.COM
3 Left Click
Command Prompt
2 Start Typing
CMD
COLLEGEOFSCRIPTING.WEEBLY.COM
Type the Word
pip
COLLEGEOFSCRIPTING.WEEBLY.COM
pip is the python package installer.
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
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
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
COLLEGEOFSCRIPTING.WEEBLY.COM
Left Click
Here
Press
COLLEGEOFSCRIPTING.WEEBLY.COM
Enter
On Keyboard
COLLEGEOFSCRIPTING.WEEBLY.COM
Notice that ourApp folder is
chosen correctly for us.
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!
COLLEGEOFSCRIPTING.WEEBLY.COM
dist
Double
Left Click
ourApp
Folder
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!
Launch Our
COLLEGEOFSCRIPTING.WEEBLY.COM
Apps Without
Showing the
Console
Window
COLLEGEOFSCRIPTING.WEEBLY.COM
then the Python Launcher Window
will NOT appear.
Greeting Message X
Hi Everyone
OK
COLLEGEOFSCRIPTING.WEEBLY.COM
Greeting Message X X
GreetingMessage
Hi
HiEveryone
Everyone
OK
OK
DATE
COLLEGEOFSCRIPTING.WEEBLY.COM
&
TIME
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
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()
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)
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()
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()
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()
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()
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()
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()
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
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()
COLLEGEOFSCRIPTING.WEEBLY.COM
opencv
COLLEGEOFSCRIPTING.WEEBLY.COM
pip install opencv-python
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
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
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()
import cv2
COLLEGEOFSCRIPTING.WEEBLY.COM
img = cv2.imread('ourImage.png',
cv2.IMREAD_GRAYSCALE)
img = cv2.imread('ourImage.png',
cv2.IMREAD_UNCHANGED)
COLLEGEOFSCRIPTING.WEEBLY.COM
theNew = cv2.imwrite("new.png", img,
[cv2.IMWRITE_PNG_COMPRESSION, 0])
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
img = cv2.imread('ourImage.png',
cv2.IMREAD_UNCHANGED)
COLLEGEOFSCRIPTING.WEEBLY.COM
theNew = cv2.imwrite("new.jpg", img,
[cv2.IMWRITE_JPEG_QUALITY, 100])
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
cv2.namedWindow("Howdy")
COLLEGEOFSCRIPTING.WEEBLY.COM
theVideo = cv2.VideoCapture(0)
while rval:
cv2.imshow("Howdy", theFrame)
rval, theFrame = theVideo.read()
key = cv2.waitKey(22)
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
COLLEGEOFSCRIPTING.WEEBLY.COM
pip install pillow
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.pack(side = "top")
ourWindow.mainloop()
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.pack(side = "top")
ourWindow.mainloop()
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.place(x = 0, y = 0)
ourWindow.mainloop()
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.pack(side = "top")
ourWindow.mainloop()
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
ourTexture = Image.open("theTexture.png")
COLLEGEOFSCRIPTING.WEEBLY.COM
ourTexture.rotate(180).show()
COLLEGEOFSCRIPTING.WEEBLY.COM
SCREEN
SHOT
ourImage = ImageGrab.grab()
COLLEGEOFSCRIPTING.WEEBLY.COM
ourImage.save('ourNewTexture.png')
ourImage = ImageGrab.grab(bbox=(0,0,900,800))
COLLEGEOFSCRIPTING.WEEBLY.COM
ourImage.save('ourNewTexture.png')
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
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
COLLEGEOFSCRIPTING.WEEBLY.COM
pip install pygame
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
COLLEGEOFSCRIPTING.WEEBLY.COM
This is the pygame
package folder.
It shows all of the
scripts and other
items that make the
pygame package work
COLLEGEOFSCRIPTING.WEEBLY.COM
VIDEO
Movie Module
COLLEGEOFSCRIPTING.WEEBLY.COM
pip install moviepy
ourVid = VideoFileClip('testMovie.mp4').resize(0.3)
COLLEGEOFSCRIPTING.WEEBLY.COM
ourVid.preview()
pygame.quit()
x = 700
COLLEGEOFSCRIPTING.WEEBLY.COM
y = 500
ourVid.preview()
pygame.quit()
import moviepy
from moviepy.editor import *
import pygame
COLLEGEOFSCRIPTING.WEEBLY.COM
ourVid = VideoFileClip('testMovie.mp4').resize(1.4)
aPortion.preview()
pygame.quit()
ourVid = VideoFileClip('testMovie.mp4').resize(1.4)
COLLEGEOFSCRIPTING.WEEBLY.COM
aPortion = ourVid.subclip(5, 20)
ourVid = aPortion.speedx(0.3)
ourVid.preview()
pygame.quit()
COLLEGEOFSCRIPTING.WEEBLY.COM
Nested
Dictionaries
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
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')
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')
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
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
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')
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')
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')
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')
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')
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
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
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
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
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
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
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)
COLLEGEOFSCRIPTING.WEEBLY.COM
answer += z + '\n'
ctypes.windll.user32.MessageBoxW(0,
answer, "The Speakers", 0)
EXTERNAL
COLLEGEOFSCRIPTING.WEEBLY.COM
FILE
Example
COLLEGEOFSCRIPTING.WEEBLY.COM
'electrons': '29' data that the
}, script on the
'Gold': next page will
{ reference!
'abbreviation': 'Au',
'electrons': '79'
}
}
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
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
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
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
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')
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
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
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
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
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
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
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
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
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
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
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
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
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
COLLEGEOFSCRIPTING.WEEBLY.COM
0111 1000 0011 1100
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
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
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
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
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
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
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
COLLEGEOFSCRIPTING.WEEBLY.COM
Reference
Updating Pip
COLLEGEOFSCRIPTING.WEEBLY.COM
python -m pip install --upgrade pip
MessageBox
COLLEGEOFSCRIPTING.WEEBLY.COM
user32
options
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, 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
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
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, 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
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, 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
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, 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
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, 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
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
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
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
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,
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
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
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()
COLLEGEOFSCRIPTING.WEEBLY.COM
ourText = messagebox.askquestion("Question",
"Are You Ready?")
#print(ourText)
Question X
if(ourText == 'yes'):
print("Pressed Yes") Are You Ready?
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()
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
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
COLLEGEOFSCRIPTING.WEEBLY.COM
List
ourList = [ 1, 2, 3, 4, 5 ]
COLLEGEOFSCRIPTING.WEEBLY.COM
print(*ourList)
output:
12345
Show All
Items in a List
College of Scripting Music & Science
Christopher Topalian
ourList = [ 1, 2, 3, 4, 5 ]
COLLEGEOFSCRIPTING.WEEBLY.COM
print(*ourList, sep=", ")
output:
1, 2, 3, 4, 5
Show All
Items in a List
College of Scripting Music & Science
Christopher Topalian
ourList = [ 1, 2, 3, 4, 5 ]
COLLEGEOFSCRIPTING.WEEBLY.COM
print(*ourList, sep="\n")
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
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
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
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
COLLEGEOFSCRIPTING.WEEBLY.COM
print(ourNumber)
COLLEGEOFSCRIPTING.WEEBLY.COM
def showInfo(self):
print("Name " + self.name + "\n" + "Kind "
+ self.kind)
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
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
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/
COLLEGEOFSCRIPTING.WEEBLY.COM
pip install Naked
COLLEGEOFSCRIPTING.WEEBLY.COM
theResponse = muterun_js('simple.js')
COLLEGEOFSCRIPTING.WEEBLY.COM
const fs = require('fs')
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__))
COLLEGEOFSCRIPTING.WEEBLY.COM
runIt.pyw simple.js test.txt
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
Exit
College of Scripting Music & Science
Christopher Topalian
do while
diagram
start
COLLEGEOFSCRIPTING.WEEBLY.COM
body
FALSE
Exit test
TRUE
while
diagram
start
COLLEGEOFSCRIPTING.WEEBLY.COM
FALSE
Exit test
TRUE
body
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
or
diagram
A
COLLEGEOFSCRIPTING.WEEBLY.COM
off
A on
and or
diagram
COLLEGEOFSCRIPTING.WEEBLY.COM
off
A B
on
A B
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