Since I have made a lot of small programs, I wanted to have a way to quickly open and close them. It was a pain to have to open Windows Explorer, navigate to the proper directory, and then select the one I wanted. While sure, this does not take too long, I know it can be faster. I used Tkinter to create a GUI (Graphical User Interface) to navigate between my programs easily.
from random import *
from turtle import *
from tkinter import *
from tkinter import scrolledtext
import sys
import os
'''
These Functions Open Previous Projects
'''
def rps():
os.system("RockPaperScissors.py")
def med():
os.system("MessageEncrypterandDecrypter.py")
def dice():
os.system("Dice.py")
def iss():
os.system("ISSLocation.py")
def art():
os.system("TurtleArt.py")
def race():
os.system("TurtleRace.py")
'''
Defining Various Variables
'''
winx = 700
winy = 600
xcoord = winx/2
wincolor = "Dodger Blue"
btn_bg = "Snow"
btn_fg = "Black"
'''
Creating The Window
'''
window = Tk()
window.title("Please Select An Item")
window.geometry('700x500')
window.configure(background = wincolor )
'''
Instruction Label
'''
lbl_rps = Label(window, text = "Select an Item to Run", font = ("TkHeadingFont", 20), bg = wincolor)
lbl_rps.place(x = xcoord, y = 50, anchor = "center")
'''
Placing Buttons
'''
btn_med = Button(window, text = "Message Encrypter / Decrypter!", command = med, bg = btn_bg, fg = btn_fg)
btn_med.place (x = xcoord, y = 150, anchor = "center")
btn_rps = Button(window, text = "Rock Paper Scissors!", command = rps, bg = btn_bg, fg = btn_fg)
btn_rps.place (x = xcoord, y = 200, anchor = "center")
btn_dice = Button(window, text = "Roll Dice!", command = dice, bg = btn_bg, fg = btn_fg)
btn_dice.place (x = xcoord, y = 250, anchor = "center")
btn_iss = Button(window, text = "Where Is The ISS?", command = iss, bg = btn_bg, fg = btn_fg)
btn_iss.place (x = xcoord, y = 300, anchor = "center")
btn_art = Button(window, text = "Create Art!", command = art, bg = btn_bg, fg = btn_fg)
btn_art.place (x = xcoord, y = 350, anchor = "center")
btn_race = Button(window, text = "Race Turtles!", command = race, bg = btn_bg, fg = btn_fg)
btn_race.place (x = xcoord, y = 400, anchor = "center")
'''
mainloop Used To Keep Window Open
'''
window.mainloop()
I was going to attach a phot of the code, but normally I do this to show the indentations. First of all, I figured out how to indent it on here earlier, plus, there is almost no indentation done here.
from random import *
from turtle import *
from tkinter import *
from tkinter import scrolledtext
import sys
import os
Nothing new imported here, except for “scrolledtext” which allowed me to create text that scrolled acorss the window. In my opion, it did not look good, so I took it out (and left it in the imports in case I wanted to add it in later). Orignally, I had done something like this: import [python file] as a way of bringing in the other programs (so when buttons are pressed, it runs a program) but then I googled discovered that I can do this:
'''
These Functions Open Previous Projects
'''
def rps():
os.system("RockPaperScissors.py")
def med():
os.system("MessageEncrypterandDecrypter.py")
def dice():
os.system("Dice.py")
def iss():
os.system("ISSLocation.py")
def art():
os.system("TurtleArt.py")
def race():
os.system("TurtleRace.py")
Simply typing os.system("[insert file name here]") allowed me to bring the other files in without a hassle. Throughout when I was typing this, I made comments explaining what each section did, to an extent.
'''
Defining Various Variables
'''
winx = 700
winy = 600
xcoord = winx/2
wincolor = "Dodger Blue"
btn_bg = "Snow"
btn_fg = "Black"
I was expirmenting with the window size, such as trying to find a good length where the buttons were centered well. winx and winy are the variables of the length and width of the window. xcoord is for placing the buttons later; it is half the width to put it in the middle. wincolor is for the background color of the window, btn_bg/fg are the background and foreground colors of the buttons. The whole list of colors is quite large:

Courtesy of http://www.science.smith.edu/dftwiki/index.php/Color_Charts_for_TKinter
'''
Creating The Window
'''
window = Tk()
window.title("Please Select An Item")
window.geometry('700x500')
window.configure(background = wincolor )
'''
Instruction Label
'''
lbl_rps = Label(window, text = "Select an Item to Run", font = ("TkHeadingFont", 20), bg = wincolor)
lbl_rps.place(x = xcoord, y = 50, anchor = "center")
To make the actual window, I did as we normally would for a Tkinter window, giving it a title and size as well as a background color. All the instruction label is, is the text at the top saying, “Select an Item to Run” (creative I know). Anchoring is exactly like an anchor, “where does this boat stop?” Choosing center simply means (can you guess it?) that the word is centered.
'''
Placing Buttons
'''
btn_med = Button(window, text = "Message Encrypter / Decrypter!", command = med, bg = btn_bg, fg = btn_fg)
btn_med.place (x = xcoord, y = 150, anchor = "center")
btn_rps = Button(window, text = "Rock Paper Scissors!", command = rps, bg = btn_bg, fg = btn_fg)
btn_rps.place (x = xcoord, y = 200, anchor = "center")
btn_dice = Button(window, text = "Roll Dice!", command = dice, bg = btn_bg, fg = btn_fg)
btn_dice.place (x = xcoord, y = 250, anchor = "center")
btn_iss = Button(window, text = "Where Is The ISS?", command = iss, bg = btn_bg, fg = btn_fg)
btn_iss.place (x = xcoord, y = 300, anchor = "center")
btn_art = Button(window, text = "Create Art!", command = art, bg = btn_bg, fg = btn_fg)
btn_art.place (x = xcoord, y = 350, anchor = "center")
btn_race = Button(window, text = "Race Turtles!", command = race, bg = btn_bg, fg = btn_fg)
btn_race.place (x = xcoord, y = 400, anchor = "center")
The second most time consuming part of this was placing buttons (the first was “discovering” how to connect files, the third was determing the amazing colorscheme of everything). I made each button follow the same template:
btn_[short name of function] = Button(window, text = "[Title of File]", command = [function name], bg = btn_bg, fg = btn_fg)
btn_[name[.place (x = xcoord, y = [whatever y coord I decided], anchor = "center")
The way I decided the y coordinates was a true feat of mathemtical reasoning. I guessed. I typed in the first one (in this case 150) and just added 50 per button – this way they are spaced out evenly. The command = [function name] is how we open the program. Once the button is clicked, it calls whichever function – and the function opens the program.
Finally, what good is a window that we can’t see? That is why I included the window.mainloop() (a built in Tkiner function) – so it loops the display until we quit.
In all the time it took to reserach and code, I could have opened each program about 10,000 times. Spend a lot of time now to save time later.