希望我能说得够具体。我正在我目前工作的地方建立一个激光切割机的培训应用程序(正如你们中的一些人最近几天看到的那样)。我已经成功地创建了一个向导,它将引导实习生完成每个过程,但我遇到了向导格式的问题。
所发生的不是出现在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发布于 2013-03-19 22:23:49
他们同时出现的原因是因为你告诉他们这样做。你的代码是这样做的:
...
page1 = Frame(wizIntro)
...
page1.pack()
page2 = Frame(wizIntro)
...
page2.pack()
...每次调用pack时,它都会将该小部件显示在屏幕上。如果您不希望它们在启动时出现,请不要在创建每个小部件后调用pack。
https://stackoverflow.com/questions/15499917
复制相似问题