title: Connecting to telegram using telethon with tkinter without freezing GUI
body: <p>I'm planning to make a simple app where I can send message to other people in telegram with a tkinter GUI without freezing. Here is my current code:</p>
  
  <pre><code>from telethon.sync import TelegramClient
  from telethon.tl.functions.messages import GetDialogsRequest
  from telethon.tl.types import InputPeerEmpty
  import tkinter as tk
  
  class TelegramApp:
      def __init__(self, master):
          width = master.winfo_screenwidth() - round(master.winfo_screenwidth() * 0.5)
          height = master.winfo_screenheight() - round(master.winfo_screenheight() * 0.1)
          x = master.winfo_screenwidth() // 2 - width // 2
          y = master.winfo_screenheight() // 2 - height // 2
          master.geometry('{}x{}+{}+{}'.format(width, height, x, y))
  
          self.btn = tk.Button(master, text="ah", command=self.connect)
          self.btn.pack(side=tk.LEFT)
  
      def connect(self):
          client.connect()
          if not client.is_user_authorized():
              client.send_code_request(phone)
              client.sign_in(phone, input('Enter the code: '))
          else:
              main()
  
  root = tk.Tk()
  app = TelegramApp(root)
  root.mainloop()
  </code></pre>
  
  <p>Right now when I click the self.btn, it freezes the GUI but it successfully connects. I'm planning to add an input box that I can enter any username, an input box where I can enter messages, both accompanied by a button that will send the message to that username. I'm also planning a list box where it will get all my groups and list it there so i can select a group etc... <strong>Basically I just want the GUI to be able to do all that work without freezing.</strong></p>