You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

64 lines
1.2 KiB

# -*- coding: utf-8 -*-
# Time : 2023/12/8 9:06
# Author : lirunsheng
# User : l'r's
# Software: PyCharm
# File : demo1.py
import tkinter as tk
def show_page(page_num):
# 隐藏所有页面
for page in pages:
page.pack_forget()
# 显示指定页面
pages[page_num].pack()
def next_page():
global current_page
if current_page < len(pages) - 1:
current_page += 1
show_page(current_page)
def prev_page():
global current_page
if current_page > 0:
current_page -= 1
show_page(current_page)
# 创建主窗口
root = tk.Tk()
# 创建页面
page1 = tk.Frame(root)
page1.pack()
tk.Label(page1, text="第一页").pack()
page2 = tk.Frame(root)
page2.pack()
tk.Label(page2, text="第二页").pack()
page3 = tk.Frame(root)
page3.pack()
tk.Label(page3, text="第三页").pack()
pages = [page1, page2, page3]
current_page = 0
# 创建翻页按钮
prev_btn = tk.Button(root, text="上一页", command=prev_page)
prev_btn.pack(side=tk.LEFT)
next_btn = tk.Button(root, text="下一页", command=next_page)
next_btn.pack(side=tk.RIGHT)
# 显示初始页面
show_page(current_page)
# 运行主循环
root.mainloop()