変更前のコード
root = tk.Tk()
root.title("温湿度計")
root.geometry("586x329")
root.configure(bg="white")
表示位置の変更方法
表示する位置をgeometry()でサイズの後ろに指定する
root.geometry("横のサイズx縦のサイズ+左からのX軸の座標+上からのY軸の座標")
変更後のコード
下記に設定すると位置が変わる
root.geometry("586x329+1500+500")
モニターの大きさを取得して座標を指定する
# ウィンドウサイズ
window_width = 586
window_height = 329
# モニターとウィンドウの中央から座標を取得
screen_width = root.winfo_screenwidth()
screen_height = root.winfo_screenheight()
x_coordinate = (screen_width // 2) - (window_width // 2) # モニター中央-ウィンドウ半分
y_coordinate = (screen_height // 2) - (window_height // 2) # モニター中央-ウィンドウ半分
root.geometry(f"{window_width}x{window_height}+{x_coordinate}+{y_coordinate}")
root.configure(bg="gray")