wxpython bind自定义_wxPython的 - 如何从自定义对话框WX

跟进的问题,我已经创建了定制dialog.It会弹出当我们从另一个函数调用的函数,如果用户点击“不要继续“按钮在对话框窗口我需要得到真/假值,以确定是否按下特定按钮,并将该值传递给函数调用以进一步处理。

但随着wx自定义对话框,我不能任何返回值,因为对话框一旦我们按任何按钮被破坏。

有没有什么办法通过按钮点击事件从自定义对话框类中获得返回值,并且即使它被销毁也可以从类外部访问。

在此先感谢。

def main():

print "start execution"

ret = getUserInput("Do you want to proceed?")

if ret:

print "proceed"

else:

print "exit"

def getUserInput(msg):

class Busy(wx.Dialog):

def __init__(self, parent, msg):

wx.Dialog.__init__(self, parent, wx.ID_ANY, "Message", size=(420, 200))

self.panel = wx.Panel(self, wx.ID_ANY)

self.label = wx.StaticText(self.panel, label=msg, pos=(20, 20))

self.gauge = wx.Gauge(self.panel, size=(300, 20), pos=(50, 50), style=wx.GA_HORIZONTAL)

self.livelabel = wx.StaticText(self.panel, label="Time to live:", pos=(50, 80))

self.lltime = wx.StaticText(self.panel, label="30", pos=(130, 80))

self.notProceedButton = wx.Button(self.panel, label="Don't proceed", pos=(50, 100))

self.timeoutButton = wx.Button(self.panel, label="Timer Off", pos=(250, 100))

self.notProceedButton.Bind(wx.EVT_BUTTON, self.notProceed)

self.timeoutButton.Bind(wx.EVT_BUTTON, self.OnNoTimeout)

self.Bind(wx.EVT_CLOSE, self.OnQuit)

self.timer = wx.Timer(self)

self.Bind(wx.EVT_TIMER, self.OnTimer, self.timer)

self.lifetimer = wx.Timer(self)

self.Bind(wx.EVT_TIMER, self.OnLifeTimer, self.lifetimer)

self.timer.Start(100)

self.lifetimer.Start(1000)

self.timeoutbutton_pressed = False

self.gauge.SetBackgroundColour(wx.Colour(0, 127, 255, 255)) # Slate Blue

self.gauge.SetRange(100)

self.gauge.SetValue(0)

self.life = 30

self.direction = 1

self.result_text = True

def OnTimer(self, evt): # Update gauge

x = int(self.gauge.GetValue())

if x == 0:

self.direction = 1

elif x == 100:

self.direction = -1

x += self.direction

self.gauge.SetValue(x)

def OnLifeTimer(self, evt): # Update time to live

if self.timeoutbutton_pressed == True:

return

self.life -= 1

self.lltime.SetLabelText(str(self.life))

if self.life < 1:

self.OnQuit(None)

def OnNoTimeout(self, evt): # toggle time to live

if self.timeoutbutton_pressed == False:

self.timeoutbutton_pressed = True

self.timeoutButton.SetLabel("Timer On")

else:

self.timeoutbutton_pressed = False

self.timeoutButton.SetLabel("Timer Off")

def OnQuit(self, event):

self.timer.Stop()

self.lifetimer.Stop()

self.Destroy()

def notProceed(self, event): # return input

self.result_text = False

self.timer.Stop()

self.lifetimer.Stop()

self.Destroy()

app = wx.App()

dlg = Busy(parent = None, msg=msg)

dlg.ShowModal()

return dlg.result_text

2017-03-14

Nithya

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值