import tkinter as tk
from tkinter import Toplevel, Button
def create_subwindow():
root_width = root.winfo_width()
root_height = root.winfo_height()
root_x = root.winfo_x()
sub_window_x = root_x + root_width + 20
sub_window_y = root.winfo_y()
sub_window = Toplevel(root)
sub_window.geometry(f"+{sub_window_x}+{sub_window_y}")
sub_window.title("子窗口")
label = tk.Label(sub_window, text="这是一个子窗口")
label.pack(pady=20)
root = tk.Tk()
root.title("主窗口")
root.geometry("300x200")
button = Button(root, text="打开子窗口", command=create_subwindow)
button.pack(pady=20)
root.mainloop()