title: Unexplained Closing Of Python Tkinter GUI using python docx
body: <p>Whenever I run this function, the function is executed, however the program then stops running/crashes, with no error code (returns 0). I honestly have no idea what is worng, although it may be due to not being able to close the docx file. I am very confused as their is <strong>no error code produced.</strong></p>
  
  <p>This type of question may not be allowed... however I believe it may provide insight into the different modules used.</p>
  
  <pre><code>def CreateAttendnaceReportScout():
  AtScout = AttendanceScout.get()
      AtScout = "".join((char for char in AtScout if char not in string.punctuation))
      print(AtScout)
      Names=AtScout.split()
      GetEventCount="SELECT present FROM eventsscouts WHERE scoutID=(SELECT scoutID FROM scoutinfo WHERE firstname=%s AND secondname=%s)"
      mycursor.execute(GetEventCount,(Names[0],Names[1]))
      myresults=mycursor.fetchall()
      print(myresults)
      NoOfEvents=0
      NoOfN=0
      NoOfY=0
      NoOfPend=0
      for i in myresults:
          NoOfEvents=NoOfEvents+1
          if i[0]==("N"):
              NoOfN=NoOfN+1
          if i[0]==("Y"):
              NoOfY=NoOfY+1
          if i[0]==("Null"):
              NoOfPend=NoOfPend+1
  
      print(NoOfEvents)
      print(NoOfN)
      print(NoOfY)
      print(NoOfPend)
      #Get List Of Events
      GetEventID = "SELECT eventID,present FROM eventsscouts WHERE scoutID=(SELECT scoutID FROM scoutinfo WHERE firstname=%s AND secondname=%s)"
      mycursor.execute(GetEventID, (Names[0], Names[1]))
      myresults=mycursor.fetchall()
      ListOfEventResponses=[]
      for i in myresults:
          print(i[0])
          GetEventName="SELECT eventname FROM events WHERE eventID=%s"
          mycursortwo.execute(GetEventName,(i[0],))
          EName=mycursortwo.fetchone()
          print(EName[0])
          Var=(i+EName)
          ListOfEventResponses.append(Var)
          print(ListOfEventResponses)
  
  
  
      AtScout="".join((char for char in AtScout if char not in string.punctuation))
      # Defining Labels For Pie Chart
      Labels = ["Present","Absent"]
      # Defining Data Variables For Each Slice Of The Pie Chart
      Slices = [NoOfY,NoOfN]
      #Removing No Value Slices
      if NoOfY==0:
          Slices.remove(NoOfY)
          Labels.remove("Present")
      if NoOfN==0:
          Slices.remove(NoOfN)
          Labels.remove("Absent")
      # Create Pie Chart Of Attendance
      Cols = ['g', 'y', 'c', 'm', 'r', 'b']
      # Plot
      plt.pie(Slices, labels=Labels, colors=Cols,
              autopct='%1.1f%%', shadow=True, startangle=140)
  
      plt.axis('equal')
      plt.title(AtScout+"'s Percentage Attendance Pie Chart")
      EPieChart = plt.gcf()
  
      PieChartFileName=AtScout+ " 's AttendancePieChart.png"
      pylab.savefig(PieChartFileName, bbox_inches='tight')
      plt.draw()
      EPieChart.savefig(PieChartFileName, bbox_inches='tight')
      plt.close()
  
  
  
  
  
  
  
      #Creating Document
      doc = docx.Document()
      run = doc.add_paragraph().add_run()
      # Apply Style
      Tstyle = doc.styles['Normal']
      font = Tstyle.font
      font.name = "Nunito Sans"
      font.size = Pt(48)
      Title = doc.add_paragraph()
      TRun = Title.add_run(AtScout+"'s Attendance Report")
      TRun.bold = True
      doc.add_picture('Scouts_Logo_Stack_Black.png', width=Inches(4.0))
      doc.add_picture(PieChartFileName, width=Inches(4.0))
      paragraph = doc.add_paragraph('')
      #Giving List Of Events And Responses
      ListOfResults= paragraph.add_run("A List Of All Events The Scout Has, Or Has Not Attended Can Be Seen Below: \n")
      ListOfResults.font.name= 'Nunito Sans'
      ListOfResults.font.size= docx.shared.Pt(20)
      for i in ListOfEventResponses:
          if i[1]==("Y"):
              ListOfResults = paragraph.add_run("The Scout Was Present At "+i[2]+"\n")
              ListOfResults.font.name = 'Nunito Sans'
              ListOfResults.font.size = docx.shared.Pt(12)
          if i[1]==("N"):
              ListOfResults = paragraph.add_run("The Scout Was Absent At "+i[2]+"\n")
              ListOfResults.font.name = 'Nunito Sans'
              ListOfResults.font.size = docx.shared.Pt(12)
          if i[1]==("Null"):
              ListOfResults = paragraph.add_run("The Scout Has Signed Up For "+i[2]+"\n")
              ListOfResults.font.name = 'Nunito Sans'
              ListOfResults.font.size = docx.shared.Pt(12)
  
  
  
      Filename=AtScout+"'s Attendance Report"
      doc.save(Filename)
  
      tk.messagebox.showinfo("Success",AtScout+"'s Attendance Report Completed!")
      raise_frame(AttendanceChoice)
  </code></pre>