title: Threads And Time + Tkinter In Python
body: <p>In tkinter I have made a password GUI some people have helped me with other things with it. The problem is: I have made a file called <code>timeload</code>in it there is a <code>while</code> loop. When I import it into my program it gets stuck on the <code>import</code>because inside of<code>timeload</code>there is the loop. I think there is a way to do it with threads but I do not know how to implement that into my code. Here is the main code:</p>
  
  <pre><code>import tkinter as tk
  from threading import Thread
  import timeload
  
  
  class FirstFrame(tk.Frame):
      trys = 3
      def __init__(self, master, **kwargs):
          tk.Frame.__init__(self, master, **kwargs)
          self.pack()
          master.title("Enter password")
          master.geometry("300x300")
          self.clock = tk.Label(self, fg='blue')
          self.clock.config(text=self.timeload.timeset())
          self.clock.pack()
          self.status2 = tk.Label(self, fg='blue')
          self.status2.pack()
          self.status = tk.Label(self, fg='red')
          self.status.pack()
          self.number = tk.Label(self, fg='red')
          self.number.pack()
          self.trysremain = tk.Label(self, fg='red')
          self.trysremain.pack()
          self.userlbl = tk.Label(self, text='Enter Username')
          self.userlbl.pack()
          self.userE = tk.Entry(self)
          self.userE.pack()
          self.userE.focus()
          self.lbl = tk.Label(self, text='Enter Password')
          self.lbl.pack()
          self.pwd = tk.Entry(self, show="*") 
          self.pwd.pack()
          self.pwd.bind('&lt;Return&gt;', self.check)
          self.btn = tk.Button(self, text="Done", command=self.check)
          self.btn.pack()
          self.btn = tk.Button(self, text="Cancel", command=self.quit)
          self.btn.pack()
  
      def check(self, event=None):
  
          if self.pwd.get() == app.password:
              if self.userE.get() == app.user:
                   self.destroy()
                   self.app= SecondFrame(self.master)
              else:
                  self.status2.config(text="Wrong Username")
  
          else:
              self.trys = self.trys - 1
              self.status.config(text="Wrong password")
              self.number.config(text=self.trys)
              self.trysremain.config(text="Trys remaining")
             if self.trys == 0:
                  root.destroy()
                  root.quit()
  
  
  class SecondFrame(tk.Frame):
      def __init__(self, master, **kwargs):
          tk.Frame.__init__(self, master, **kwargs)
          self.pack()
          master.title("Main Application")
          master.geometry("600x400")
          self.c = tk.Button(self, text="Options", command=self.third_frame_open)
          self.c.pack()
  
      def third_frame_open(self):
          self.destroy()
          self.app= ThirdFrame(self.master)
  
  
  class ThirdFrame(tk.Frame):
      def __init__(self, master, **kwargs):
          tk.Frame.__init__(self, master, **kwargs)
          self.pack()
          self.password_set = tk.Label(self, fg='green')
          self.password_set.pack()
          master.title("Options")
          master.geometry("400x300")
          self.but2 = tk.Button(self, text="Go Back",     command=self.second_frame_open)
          self.but2.pack()
          self.but1 = tk.Button(self, text="Change password", command=self.showpasswordinput)
          self.but1.pack()
          self.but1.bind('&lt;Return&gt;', self.showpasswordinput)
  
      def showpasswordinput(self):
          self.but1.pack_forget()
          self.e = tk.Entry(self.master, show="*")
          self.e.pack()
          self.e.focus()
          self.but2 = tk.Button(self, text="Change password", command=self.set_password)
         self.but2.pack()
          self.but2.bind('&lt;Return&gt;', self.set_password)
  
      def set_password(self):
          self.password_set.config(text="Password Updated")
          setpass = open("password_store.txt", "w")
          passvar = self.e.get()
          self.e.pack_forget()
          setpass.write(passvar)
          setpass.close()
  
      def second_frame_open(self):
          self.destroy()
          self.app= SecondFrame(self.master)
  
  if __name__=="__main__":
      root = tk.Tk()
      app=FirstFrame(root)
      user = open("user_store.txt", "r")
      app.user = user.read()
      user.close()
      password2 = open("password_store.txt", "r")
      app.password = password2.read()
      password2.close()
      root.mainloop()
  </code></pre>
  
  <p>Here is the code in the <code>timeload</code>:</p>
  
  <pre><code>import datetime
  timeload = ('on')
  while timeload == ('on'):
      timeset = datetime.datetime.now()
  </code></pre>
  
  <p>Thanks,
  Jake</p>