当前位置: 首页 > news >正文

python tk实现标签切换页面

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()

http://www.lryc.cn/news/365548.html

相关文章:

  • 引擎:UI
  • Redis常见异常及优化方案
  • YOLOV5 图像分割:利用yolov5进行图像分割
  • 如何在Linux中使用Screen管理后台进程
  • 互联网轻量级框架整合之SpringMVC初始化及各组件工作原理
  • 【Android面试八股文】finally中的代码一定会执行吗?try里有return,finally还执行么?
  • 微服务第一轮
  • Linux 命令 FIO:深入理解磁盘性能测试工具
  • 《精通ChatGPT:从入门到大师的Prompt指南》大纲目录
  • Go_context包
  • Mysql基础进阶速成版
  • Tomcat安装与配置要点和难点以及常见报错和解决方案
  • 【Oracle】Oracle导入导出dmp文件
  • 渗透测试模拟实战-tomexam网络考试系统
  • “神经网络之父”和“深度学习鼻祖”Geoffrey Hinton
  • [消息队列 Kafka] Kafka 架构组件及其特性(一)
  • 【Flutter 面试题】 JIT 与 AOT分别是什么?
  • QT获取最小化,最大化,关闭窗口事件
  • Oracle作业调度器Job Scheduler
  • Vue 组件之间的通信
  • Elementary OS 7.1简单桌面调整
  • 【C++ | 析构函数】类的析构函数详解
  • ceph radosgw 原有zone placement信息丢失数据恢复
  • ​​​​【动手学深度学习】残差网络(ResNet)的研究详情
  • freertos初体验 - 在stm32上移植
  • ubuntu使用 .deb 文件安装VScode
  • 9.1.1 简述目标检测领域中的单阶段模型和两阶段模型的性能差异及其原因
  • 系统化自学Python的实用指南
  • 加密货币初创企业指南:如何寻找代币与市场的契合点
  • 【十二】图解mybatis日志模块之设计模式