title: Python : How to center Label in tkinter window
body: <p>I'm trying to construct a popup window, containing varying text message for user to respond.</p>
  
  <p>I seek a way to center the text (Label) and Button inside that window- with no success.</p>
  
  <p><a href="https://i.stack.imgur.com/CJS3Q.gif" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/CJS3Q.gif" alt="Popup window"></a></p>
  
  <p>Popup Window has a determind size. Centering the frame inside it should take into account width and height of textlabel ( defined in amount of letters ).</p>
  
  <p>As you can see in code, <code>w</code>, <code>h</code> defines window's size, <code>xbias</code>,<code>ybias</code> have an expression to center <code>testframe</code> (both contains <code>alpha1</code>, <code>alpha2</code> as a correction factor for text's size ) </p>
  
  <p>I'm seeking the mathematical expression for <code>alpha1</code>, <code>alpha2</code> ( which equal for 1 for now )... or a better way to construct such a popup window.</p>
  
  <pre><code>root = Tk()
  w = '400'
  h = '100'
  root.geometry('{}x{}'.format(w, h))
  root.configure(bg='lightgreen')
  
  txt = StringVar()
  txt.set("This is an error message")
  
  alpha1 = 1
  alpha2 = 1
  xbias = int(w) / 2 - (len(txt.get()) / 2) * alpha1
  ybias = int(h) / 2 - alpha2
  
  testframe = ttk.Frame(root)
  testframe.grid(row=0, column=1, pady=ybias, padx=xbias)
  
  label1 = ttk.Label(testframe, textvariable=txt)
  label1.grid(row=0, column=0)
  </code></pre>