def center_window(widget, width=None, height=None):
    """ Centres widget in the middle of the screen.

        Args:
            widget (Tk object): widget that needs to be centred.
            width (int, optional): width of the widget that should be used.
                If not specified, widget width is used.
            height (int, optional): height of the widget that should be used.
                If not specified, widget width is used.
    """
    widget.withdraw()
    widget.update_idletasks()
    if width is None:
        width = widget.winfo_reqwidth()
    if height is None:
        height = widget.winfo_reqheight()
    sw = widget.winfo_screenwidth()
    sh = widget.winfo_screenheight()
    x = (sw - width) / 2
    y = (sh - height) / 2
    widget.geometry('%dx%d+%d+%d' % (width, height, x, y))
    widget.deiconify()
