如何防止tkinter向导格式一次显示所有页面?

时间:2013-03-19 12:46:49

标签: tkinter wizard

希望我能够做到这一点。我正在我目前的工作地点建立一个激光切割机培训应用程序(正如你们最近几天看到的那样)。我已经能够成功创建一个向导,让学员完成每个过程,但我遇到了向导格式的问题。

发生的事情不是Python Shell中出现的错误,因此就解释器而言,代码没有问题。但是,当我打开向导时,它想要一次显示所有页面。我可以点击“下一个”和“上一个”按钮,它会清除,但我无法完成第四页,因为它会将按钮推出屏幕,因此无法触及(我的屏幕分辨率)不允许整个窗口适合,并且按钮始终从底部开始,无论指定的位置如何。)

如果有人能告诉我导致问题的原因以及如何解决问题,我将非常感谢您的帮助。

我发布了以下代码。我只是要求理解,因为这是我自从几年前使用C ++制作的基于DOS的计算器以来构建的最复杂的应用程序。换句话说,这是我的第一个带GUI的应用程序,也是我在python中的第一个应用程序。因此,我对python的体验以及stackoverflow就此而言非常有限。

请注意,加载的某些模块不是向导的一部分。他们在应用程序的其他地方发挥作用。

#Import the Modules required for proper app function
import os, cgi, pickle
from os.path import *
from tkinter import *
import tkinter

#All other windows must be created as Definitions before the Home Screen/Main Menu is coded.
#All Button Commands must be created as Definitions before their respective windows

#Start Code for the Introduction Wizard
def wizIntro():
    wizIntro = tkinter.Tk()

    #Title:
    wizIntro.title('Welcome to Training')

    #Content:
    page1 = Frame(wizIntro)
    Label(page1, text='', width=110).pack()
    Label(page1, text='--Welcome to Training--', width=85).pack()
    Label(page1, text='', width=85).pack()
    Label(page1, text='This tutorial will help you familiarize yourself with the program.  Following it is key to understanding', width=85).pack()
    Label(page1, text='the proper operation of the Laser Cutter.', width=85).pack()
    Label(page1, text='', width=90).pack()
    Label(page1, text='It is also important to follow every insrtuction exactly as stated, to avoid or minimize damage to the Laser', width=85).pack()
    Label(page1, text='Cutter and reduce the risk of injury to the operator and those around him.', width=85).pack()
    Label(page1, text='Therefore, all safety notices must be followed with extreme care.', width=110).pack()
    Label(page1, text='--Failure to follow all safety notices poses a severe risk of damage to the equipment and to the operator, which can be fatal--', width=110, fg='red').pack()
    Label(page1, text='', width=110).pack()
    Label(page1, text='', width=110).pack()
    Label(page1, text='', width=110).pack()
    Label(page1, text='Click Next to Continue...').pack(side = BOTTOM)
    page1.pack()

    page2 = Frame(wizIntro)
    Label(page2, text='', width=110).pack()
    Label(page2, text='Notice:  Before anyone can operate the Laser Cutter, they must have completed this training program and be authorized as an operator.', width=110).pack()
    Label(page2, text='FAILURE TO FOLLOW THIS POLICY MAY RESULT IN IMMEDIATE TERMINATION OF EMPLOYMENT', fg='red').pack()
    Label(page2, text='', width=110).pack()
    Label(page2, text='Once again, it is very important to follow all safety precautions and notices.  Failure to do so can result in one or more of the following:', width=110).pack()
    Label(page2, text='*Severe burning', width=110).pack()
    Label(page2, text='*Severe damage to, or loss of, fingers', width=110).pack()
    Label(page2, text='*Temporary or permanent blindness', width=110).pack()
    Label(page2, text='*Minor to Severe damage to the Laser Cutter and/or its components', width=110).pack()
    Label(page2, text='', width=110).pack()
    Label(page2, text='On the next screen, you will see a list of precautions to follow.', width=110).pack()
    Label(page2, text='', width=110).pack()
    Label(page2, text='', width=110).pack()
    Label(page2, text='...Click Previous to go Back, or Click Next to Continue...').pack(side = BOTTOM)
    page2.pack()

    page3 = Frame(wizIntro)
    Label(page3, text='', width=110).pack()
    Label(page3,  text='--Safety Precautions--', width=110).pack()
    Label(page3, text='', width=110).pack()
    Label(page3, text='1.  Do not look at the laser tube or at the laser strike-point without proper eyewear or through the glass on the Laser Cutter.', width=110).pack()
    Label(page3, text='2.  Do not attempt to overide the Door Safety Sensor to allow the laser to cut with the door open.', width=110).pack()
    Label(page3, text='3.  Keep hands clear of all moving parts and refrain from touching the mirrors with bare hands.', width=110).pack()
    Label(page3, text='4.  Do not make any adjustments to the laser calibration without proper training and authorization from your superviser.', width=110).pack()
    Label(page3, text='5.  Do not remove any covers except for the bottom-front (and only to empty the boxes behind said cover) without permission.', width=110).pack()
    Label(page3, text='6.  Keep a constant awareness and/or watch on the laser as it cuts, and cancel the cut-cycle as soon as problems occur,', width=110).pack()
    Label(page3, text='such as fires or when stamps catch on the Laser Head.', width=110).pack()
    Label(page3, text='7.  Report any problems that will cause the Laser Cutter to not operate properly to your supervisor immediately.', width=110).pack()
    Label(page3, text='Above all else, make safety your Highest Priority', width=110, fg='red').pack()
    Label(page3, text='', width=110).pack()
    Label(page3, text='...Click Previous to go Back, or Click Next to Continue...').pack(side = BOTTOM)
    page3.pack()

    page4 = Frame(wizIntro)
    Label(page4, text='', width=110).pack()
    Label(page4, text='...Click Previous to go Back, or Click Next to Continue...').pack(side = BOTTOM)
    page4.pack()

    #Commands:
    pages = [page1, page2, page3, page4]
    current = page1
    def move(dirn):
        nonlocal current
        idx = pages.index(current) + dirn
        if not 0 <= idx < len(pages):
            return
        current.pack_forget()
        current = pages[idx]
        current.pack(side = TOP)

    def nex():
        move(+1)

    def prev():
        move(-1)

    Button(wizIntro, text='Previous', command=prev).pack(side = LEFT)
    Button(wizIntro, text='Next', command=nex).pack(side = RIGHT)

    #End Code for the Introduction Wizard

1 个答案:

答案 0 :(得分:1)

他们一下子出现的原因是因为你告诉他们。您的代码执行此操作:

...
page1 = Frame(wizIntro)
...
page1.pack()
page2 = Frame(wizIntro)
...
page2.pack()
...

每次拨打pack时,都会将该小部件放在屏幕上。如果您不希望它们在启动时出现,请不要在创建每个小部件后调用pack