I am receiving an error message that says that the application has been destroyed. I already got a response on an earlier incomplete version of the code that didn't fix the issue so I am getting a little concerned. I am very new to tkinter so I'm not too good at this.
from tkinter import *
from tkinter import ttk
from tkinter import filedialog
from PIL import ImageTk, Image
import numpy as np
import matplotlib.pyplot as plt
import os
import glob
root = Tk()
e = Entry(root, width = 50)
e.pack()
root.title("Insert GUI Title Here")
root.geometry('600x400+50+50')
root.resizable(False, False)
nameDirections = []
directions = []
def openSmFile():
folPath = filedialog.askdirectory()
return folPath
root.mainloop()
def checkDirections():
folPath = openSmFile()
for fpath in glob.iglob(f'{folPath}/*'):
if (fpath.endswith('.sm')):
file = open(fpath,"r")
lines = []
lines = file.readlines()
left = 0
down = 0
up = 0
right = 0
beats = 0
for line in lines:
i = 0
if not ("," in line or "." in line or "#" in line or ";" in line or "-" in line or line == ""):
for alpha in line:
if i == 0 and alpha != "0":
left += 1
if i == 1 and alpha != "0":
down += 1
if i == 2 and alpha != "0":
up += 1
if i == 3 and alpha != "0":
right += 1
i += 1
beats += 1
print ("There are " + str(left) + " lefts in this song.")
print ("There are " + str(down) + " downs in this song.")
print ("There are " + str(up) + " ups in this song.")
print ("There are " + str(right) + " rights in this song.")
print ("There are " + str(beats) + " beats.")
nameDirections = ["left", "down", "up", "right"]
directions = [left, down, up, right]
runThrough = Button(
root,
padx=50,
pady=50,
text="Click to print number of each arrow",
command=checkDirections
)
runThrough.pack()
runThrough.grid(row = 0, column = 0)
def barGraph():
LabelBar = Label(root, text = "Bar Activated")
LabelBar.pack()
fig = plt.figure()
plt.title("Directions")
ax = fig.add_axes([0,0,1,1])
ypos = np.arange(len(nameDirections))
plt.bar(nameDirections, directions)
plt.show()
def ILovePie():
LabelPie = Label(root, text = "Pie Activated")
LabelPie.pack()
plt.title("Directions")
fig = plt.figure()
ax = fig.add_axes([0,0,1,1])
ypos = np.arange(len(nameDirections))
plt.pie(directions, labels = nameDirections,autopct='%1.1f%%',
shadow=True, startangle=90)
plt.show()
barGraph = Button(root, text = "Click to show a bar graph", padx = 50, pady = 50, command = barGraph())
barGraph.grid(row = 1, column = 5)
runThrough.pack()