title: Memory leak when using threads and tkinter
body: <p>I have this "game thing" I've been working on for a while. It works perfectly, except that when I close the GUI whithout having finished the game, it keeps running on the background, (like if it was memory leaking, even though "real" memory leaking doesn't work that way).</p>
  
  <p>This game runs (or in theory it should) on two threads, one for the GUI and another for the game itself, after some research I've found out I could use the <code>.protocol()</code> method on my root widget to execute <code>raise SystemExit</code> to ensure all threads were terminated when the GUI was closed. But it appears not to be working and I have no clue why. Here's the code:</p>
  
  <pre><code># -*- coding: UTF-8 -*-
  from tkinter import Tk, Label, Entry, Button, W, E, END
  from threading import Thread
  from random import randint
  class GUI(Thread):
      tentativas = []
      def __init__(self):
          Thread.__init__(Thread)
          self.start()
          self.valor = randint(0, 100)
          self.vidas = 6
          self.venceu = False
          self.entry, self.aux = -128, -128
          while self.vidas &gt; 0:
              self.vidas -= 1
              while True:
                  if self.entry != self.aux:
                      break
              self.aux = self.entry
              if self.entry == self.valor:
                  self.txt01.config(text = "Congrats, you won!", fg = "green")
                  self.venceu = True
                  self.txt02.config(text = '')
                  break
              elif self.entry &gt; self.valor:
                  self.txt01.config(text = 'Too big, try again.')
              else:
                  self.txt01.config(text = 'Too small, try again.')
              self.txt02.config(text = str(self.vidas) + ' Chances restantes.')
          if self.venceu != True:
              self.txt01.config(text = 'You ran out of lives, game over!')
              self.txt02.config(text = 'The number was ' + str(self.valor) + '.')
      def run(self):
          self.root = Tk()
          self.root.title("Lottery")
          self.txt00 = Label(self.root, text = "Welcome, insert a number ranging from 0 to 100:")
          self.txt00.grid(sticky = W, columnspan = 4)
          self.txt01 = Label(self.root, text = " ")
          self.txt01.grid(row = 1, column = 0, columnspan = 4, sticky = W)
          self.txt02 = Label(self.root, text ="6 Tentativas restantes.")
          self.txt02.grid(row = 4, columnspan = 2, sticky = E)
          self.inp00 = Entry(self.root)
          self.inp00.grid(row = 2,columnspan = 2,column = 1,sticky = W)
          self.but00 = Button(self.root, text = "Try!", command = self.chutar)
          self.root.bind("&lt;Return&gt;", self.chutar)
          self.but00.grid(row = 2, column = 3)
          self.root.protocol("WM_DELETE_WINDOW", self.killGUI)
          self.root.mainloop()
      def chutar(self, args = None):
          self.pular = True
          try:
              self.chute = int(self.inp00.get())
          except ValueError:
              self.txt01.config(text = "Invalid entry, try again!", fg = "red")
              self.pular = False
          finally:
              self.inp00.delete(0, END)
          if self.pular:
              if self.chute in range(101) and self.chute not in self.tentativas:
                  self.entry = self.chute
                  self.tentativas.append(self.entry)    
              else:
                  self.var = "Invalid entry, try again!"
                  self.txt01.config(text = self.var, fg = "red")
      def killGUI(self):
          raise SystemExit
  k = GUI()
  </code></pre>
  
  <p>I really don't know why the "killGUI" function isn't working, please help me!</p>