0

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

发生的事情不是 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
4

1 回答 1

1

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

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

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

于 2013-03-19T14:23:49.337 回答