Python 如何设置正在按下的取消按钮
您好,我使用了Python 如何设置正在按下的取消按钮,python,wxpython,Python,Wxpython,您好,我使用了wxpython4和windows10。我想在我的应用程序中集成PyProgress(AGW)和取消按钮,我希望此按钮取消将我的应用程序暂停。除了我添加了取消按钮,但它是不可点击的,我不能绑定暂停功能与此按钮 import wx.lib.agw.pyprogress as PP def onButton(self, event): """ Based on the wxPython demo by the same name """
wxpython4
和windows10
。我想在我的应用程序中集成PyProgress(AGW)
和取消按钮
,我希望此按钮取消
将我的应用程序暂停
。除了我添加了取消按钮,但它是不可点击的,我不能绑定暂停功能与此按钮
import wx.lib.agw.pyprogress as PP
def onButton(self, event):
"""
Based on the wxPython demo by the same name
"""
event.Skip()
dlg = PP.PyProgress(None, -1, "Demo", "Demo in progress", agwStyle=wx.PD_APP_MODAL | wx.PD_ELAPSED_TIME | wx.PD_CAN_ABORT)
dlg.SetGaugeProportion(0.2)
dlg.SetGaugeSteps(50)
dlg.SetGaugeBackground(wx.WHITE)
dlg.SetFirstGradientColour(wx.WHITE)
dlg.SetSecondGradientColour(wx.BLUE)
max = 400
keepGoing = True
count = 0
while keepGoing and count < max:
count += 1
wx.MilliSleep(30)
if count >= max / 2:
keepGoing = dlg.UpdatePulse("Half-time!")
else:
keepGoing = dlg.UpdatePulse()
dlg.Destroy()
#if(wx.PD_CAN_ABORT):
#execute onPause(event)
def onPause(self, event):
???
导入wx.lib.agw.pyprogress作为PP
def ON按钮(自身、事件):
"""
基于同名的wxPython演示
"""
event.Skip()
dlg=PP.PyProgress(无,-1,“演示”,“演示进行中”,agwStyle=wx.PD_应用程序|模式| wx.PD_已用时间| wx.PD_可|中止)
dlg.设置量规比例(0.2)
dlg.设置计量器(50)
dlg.设置仪表背景(宽x.白色)
dlg.SetFirstGradientColor(宽x.白色)
dlg.SetSecondGradientColor(wx.BLUE)
最大值=400
继续=正确
计数=0
在保持和计数<最大值时:
计数+=1
wx.MilliSleep(30)
如果计数>=最大值/2:
keepGoing=dlg.UpdatePulse(“一半时间!”)
其他:
keepGoing=dlg.UpdatePulse()
dlg.Destroy()
#如果(wx.PD_可以_中止):
#执行onPause(事件)
def onPause(自我、事件):
???
PyProgress
似乎不再具有可操作的取消按钮。
改用wx.ProgressDialog
或wx.Gauge
如果您不想使用暂停功能,请使用以下内容:
import wx
class PyProgressDemo(wx.Frame):
def __init__(self, parent):
super().__init__(parent)
self.panel = wx.Panel(self, -1)
self.startbutton = wx.Button(self.panel, -1, "Start PyProgress!")
self.startbutton.Bind(wx.EVT_BUTTON, self.onButton)
vbox = wx.BoxSizer(wx.VERTICAL)
vbox.Add(self.startbutton)
self.panel.SetSizer(vbox)
self.Show()
def onButton(self, event):
self.dlg = wx.ProgressDialog('Search personal Data', 'Analyse en cours..', style= wx.PD_ELAPSED_TIME | wx.PD_CAN_ABORT)
max = 400
keepGoing = True
count = 0
while keepGoing and count < max:
count += 1
wx.MilliSleep(30)
if count >= max / 2:
(keepGoing, skip) = self.dlg.Pulse("Half-time!")
else:
(keepGoing, skip) = self.dlg.Pulse()
self.dlg.Destroy()
app = wx.App()
prog = PyProgressDemo(None)
app.MainLoop()
import wx
class PyProgressDemo(wx.Frame):
def __init__(self, parent):
super().__init__(parent)
self.panel = wx.Panel(self, -1)
self.startbutton = wx.Button(self.panel, -1, "Start PyProgress!")
self.stopbutton = wx.Button(self.panel, -1, "Pause/Unpause PyProgress!")
self.startbutton.Bind(wx.EVT_BUTTON, self.onButton)
self.stopbutton.Bind(wx.EVT_BUTTON, self.onPause)
vbox = wx.BoxSizer(wx.VERTICAL)
vbox.Add(self.startbutton)
vbox.Add(self.stopbutton)
self.panel.SetSizer(vbox)
self.Show()
def onButton(self, event):
self.dlg = wx.ProgressDialog('Search personal Data', 'Analyse en cours..', style= wx.PD_ELAPSED_TIME | wx.PD_CAN_ABORT)
max = 400
keepGoing = True
count = 0
try:
while keepGoing and count < max:
if self.dlg.IsFrozen():
wx.Yield()
wx.MilliSleep(30)
continue
count += 1
wx.MilliSleep(30)
if count >= max / 2:
(keepGoing, skip) = self.dlg.Pulse("Half-time!")
else:
(keepGoing, skip) = self.dlg.Pulse()
self.dlg.Destroy()
except:
pass
def onPause(self, event):
try:
if self.dlg.IsFrozen():
self.dlg.Thaw()
else:
self.dlg.Freeze()
except:
pass
app = wx.App()
prog = PyProgressDemo(None)
app.MainLoop()
现在我想将“取消”改为“暂停”,并在“ProgressDialog”上再添加两个按钮(重新启动,其他)。即使您必须修改库的源代码。我会的。但是请告诉我在哪里可以找到要编辑的文件。@LandryEngolo您必须阅读python子类化
,因为您要对progressdialog子类化。