【发布时间】:2019-11-18 15:16:32
【问题描述】:
我试图更好地理解 wxPython 如何“扫描”。
请看我下面的代码:
import os
import wx
from time import sleep
NoFilesToCombine = 0
class PDFFrame(wx.Frame):
def __init__(self, parent, title):
wx.Frame.__init__(self, parent, -1, title, size=(400,400))
panel = wx.Panel(self)
self.Show()
try: #Set values of PDFNoConfirmed to zero on 1st initialisation
if PDFNoConfimed != 0:
None
except UnboundLocalError:
PDFNoConfimed = 0
try: #Set values of PDFNoConfirmed to zero on 1st initialisation
if PDFNoConfirmedInitially != 0:
None
except UnboundLocalError:
PDFNoConfirmedInitially = 0
while ((PDFNoConfimed == 0) and (PDFNoConfirmedInitially == 0)):
while PDFNoConfirmedInitially == 0:
BoxInputNo = wx.NumberEntryDialog(panel, "So You Want To Combine PDF Files?", "How Many?", "Please Enter", 0, 2, 20)
if BoxInputNo.ShowModal() == wx.ID_OK: #NumberEntryDialog Pressed OK
NoFilesToCombine = BoxInputNo.GetValue()
PDFNoConfirmedInitially = 1
elif BoxInputNo.ShowModal() == wx.ID_CANCEL:
exit()
print(NoFilesToCombine)
ConfirmationLabel = wx.StaticText(panel, -1, label="You Have Selected " + str(NoFilesToCombine) + " Files To Combine, Is This Right?", pos=(20, 100))
ConfirmationBoxConfirm = wx.ToggleButton(panel, label="Confirm", pos=(20, 200))
ConfirmationBoxCancel = wx.ToggleButton(panel, label="Cancel", pos=(180, 200))
#if ConfirmationBoxConfirm.GetValue() == 1:
# exit()
if ConfirmationBoxCancel.GetValue() == 1:
PDFNoConfirmedInitially = 0
app = wx.App()
frame = PDFFrame(None, title="Robs PDF Combiner Application")
app.MainLoop()
现在这是一项正在进行的工作,因此显然还没有完成。但是,我想通过上述方式完成的是:
显示一个数字输入弹出窗口。如果用户按“取消”退出应用程序(这可行,但由于某种原因需要按 2 次?)。如果按 OK,则:
显示在步骤 1 中输入的数字,带有 2 个附加按钮。 “确认”尚未执行任何操作,但“取消”应将您带回第 1 步。(通过重置
PDFNoConfirmedInitially标志)。
现在第 2 步不起作用。当我调试它几乎看起来好像PDFFrameonly 被扫描一次。我可能错误的假设是,由于app.MainLoop() 不断扫描 wx.App() 而这又会调用子框架,这将被不断扫描?
帮助/指点/更深层次的理解总是很感激,
谢谢 抢
【问题讨论】: