我一直在研究 python3 中的 tkinter,发现很难在网上找到好的文档和答案。为了帮助其他遇到相同问题的人,我决定发布一个简单问题的解决方案,该问题似乎没有在线文档。
问题:创建一个类似向导的程序,该程序向用户显示一系列窗口,用户可以在单击下一步和后退按钮的窗口之间移动。
解决办法是:
grid_forget()方法隐藏每个帧,但不隐藏第一帧,使其成为可见帧。框架上的所有子小部件都将与框架一起隐藏。grid_forget())并使需要的框架可见(使用grid())。因此,您将创建一个窗口并在其上显示不同的框架。
(顺便说一下,开始学习 tkinter 的最佳地点是:http : //www.tkdocs.com/tutorial/index.html)
这是 Python3 中的示例实现。它有 3 个简单的窗口,每个窗口都有一个文本标签和两个用于浏览不同窗口的按钮。
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#
# Creates three "windows" that the user can navigate through using Back and Next - buttons.
import tkinter
import tkinter.ttk
def create_widgets_in_first_frame():
# Create the label for the frame
first_window_label = tkinter.ttk.Label(first_frame, text='Window 1') …Run Code Online (Sandbox Code Playgroud)