import tkinter as tk
from tkinter import ttk# 初始化主窗口
root = tk.Tk()
root.title("标签页示例")# 设置窗口大小
root.geometry("400x300")# 创建 Notebook 小部件
notebook = ttk.Notebook(root)
notebook.pack(expand=True, fill="both")# 创建两个Frame,作为两个标签页的内容
page1 = ttk.Frame(notebook)
page2 = ttk.Frame(notebook)
page3 = ttk.Frame(notebook)# 将Frame添加到Notebook中,同时设置标签名称
notebook.add(page1, text="页面 1")
notebook.add(page2, text="页面 2")
notebook.add(page3, text="页面 3")# 页面1的内容
# 单选框
radio_var = tk.IntVar()
radio1 = ttk.Radiobutton(page1, text="选项1", variable=radio_var, value=1)
radio2 = ttk.Radiobutton(page1, text="选项2", variable=radio_var, value=2)
radio3 = ttk.Radiobutton(page1, text="选项3", variable=radio_var, value=3)
radio1.grid(row=0, column=0, sticky=tk.W)
radio2.grid(row=1, column=0, sticky=tk.W)
radio3.grid(row=2, column=0, sticky=tk.W)# 输入框
entry1 = ttk.Entry(page1)
entry2 = ttk.Entry(page1)
entry1.grid(row=3, column=0, padx=20, pady=5)
entry2.grid(row=4, column=0, padx=20, pady=5)# 按钮
button1 = ttk.Button(page1, text="按钮1")
button2 = ttk.Button(page1, text="按钮2")
button3 = ttk.Button(page1, text="按钮3")
button1.grid(row=5, column=0, pady=5)
button2.grid(row=5, column=1, pady=5)
button3.grid(row=5, column=2, pady=5)# 页面2的内容
# 标签文本
label1 = ttk.Label(page2, text="这是页面 2 的标签1")
label2 = ttk.Label(page2, text="这是页面 2 的标签2")
label1.pack(pady=5)
label2.pack(pady=5)# 输入框
entry_page2 = ttk.Entry(page2)
entry_page2.pack(pady=5)# 按钮
button_page2 = ttk.Button(page2, text="页面2的按钮")
button_page2.pack(pady=5)# 运行主循环
root.mainloop()


