用wxPython建立自銷燬皮膚的方法
The other day I saw a question on StackOverflow about how to dynamically destroy and create panels after a certain amount of time has passed. I told the fellow that he could use the examples from one of my blog articles where I destroyed and created buttons, but the dude just didn’t get it.
So I wrote a simple example where the panel displays a count down and then destroys itself and is promptly replaced with another panel.
Here’s the code for your viewing pleasure:
02.
03.########################################################################
04.class PanelOne(wx.Panel):
05.""""""
06.
07.#----------------------------------------------------------------------
08.def __init__(self, parent):
09."""Constructor"""
10.wx.Panel.__init__(self, parent)
11.
12.self.countdown = wx.StaticText(self, label="This panel will self-destruct in 10 seconds")
13.
14.
15.########################################################################
16.class PanelTwo(wx.Panel):
17.""""""
18.
19.#----------------------------------------------------------------------
20.def __init__(self, parent):
21."""Constructor"""
22.wx.Panel.__init__(self, parent)
23.
24.txt = wx.StaticText(self, label="Panel Two")
25.
26.
27.########################################################################
28.class MainFrame(wx.Frame):
29.""""""
30.
31.#----------------------------------------------------------------------
32.def __init__(self):
33."""Constructor"""
34.wx.Frame.__init__(self, None, title="Panel Smacker")
35.self.panelOne = PanelOne(self)
36.self.time2die = 10
37.
38.self.timer = wx.Timer(self)
39.self.Bind(wx.EVT_TIMER, self.update, self.timer)
40.self.timer.Start(1000)
41.
42.self.sizer = wx.BoxSizer(wx.VERTICAL)
43.self.sizer.Add(self.panelOne, 1, wx.EXPAND)
44.self.SetSizer(self.sizer)
45.
46.#----------------------------------------------------------------------
47.def update(self, event):
48.""""""
49.if self.time2die < 0:
50.self.panelOne.Destroy()
51.self.panelTwo = PanelTwo(self)
52.self.sizer.Add(self.panelTwo, 1, wx.EXPAND)
53.self.Layout()
54.self.timer.Stop()
55.else:
56.msg = "This panel will self-destruct in %s seconds" %self.time2die
57.self.panelOne.countdown.SetLabel(msg)
58.self.time2die -= 1
59.
60.if __name__ == "__main__":
61.app = wx.App(False)
62.frame. = MainFrame()
63.frame.Show()
64.app.MainLoop()
So I wrote a simple example where the panel displays a count down and then destroys itself and is promptly replaced with another panel.
Here’s the code for your viewing pleasure:
CODE:
01.import wx02.
03.########################################################################
04.class PanelOne(wx.Panel):
05.""""""
06.
07.#----------------------------------------------------------------------
08.def __init__(self, parent):
09."""Constructor"""
10.wx.Panel.__init__(self, parent)
11.
12.self.countdown = wx.StaticText(self, label="This panel will self-destruct in 10 seconds")
13.
14.
15.########################################################################
16.class PanelTwo(wx.Panel):
17.""""""
18.
19.#----------------------------------------------------------------------
20.def __init__(self, parent):
21."""Constructor"""
22.wx.Panel.__init__(self, parent)
23.
24.txt = wx.StaticText(self, label="Panel Two")
25.
26.
27.########################################################################
28.class MainFrame(wx.Frame):
29.""""""
30.
31.#----------------------------------------------------------------------
32.def __init__(self):
33."""Constructor"""
34.wx.Frame.__init__(self, None, title="Panel Smacker")
35.self.panelOne = PanelOne(self)
36.self.time2die = 10
37.
38.self.timer = wx.Timer(self)
39.self.Bind(wx.EVT_TIMER, self.update, self.timer)
40.self.timer.Start(1000)
41.
42.self.sizer = wx.BoxSizer(wx.VERTICAL)
43.self.sizer.Add(self.panelOne, 1, wx.EXPAND)
44.self.SetSizer(self.sizer)
45.
46.#----------------------------------------------------------------------
47.def update(self, event):
48.""""""
49.if self.time2die < 0:
50.self.panelOne.Destroy()
51.self.panelTwo = PanelTwo(self)
52.self.sizer.Add(self.panelTwo, 1, wx.EXPAND)
53.self.Layout()
54.self.timer.Stop()
55.else:
56.msg = "This panel will self-destruct in %s seconds" %self.time2die
57.self.panelOne.countdown.SetLabel(msg)
58.self.time2die -= 1
59.
60.if __name__ == "__main__":
61.app = wx.App(False)
62.frame. = MainFrame()
63.frame.Show()
64.app.MainLoop()
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/301743/viewspace-734244/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- 建立和銷燬物件物件
- 建立和銷燬物件(一)物件
- 【Java基礎】建立和銷燬物件Java物件
- Android執行緒的建立與銷燬Android執行緒
- Java高階教程 - 建立和銷燬物件Java物件
- python例項建立銷燬的函式整理Python函式
- 防止ViewPager中的Fragment被銷燬的方法ViewpagerFragment
- Flutter 應用程式建立一個擴充套件皮膚列表Flutter套件
- Python __del__方法:銷燬物件Python物件
- win10控制皮膚在哪裡 win10如何開啟控制皮膚的方法Win10
- win10控制皮膚在哪裡 win10控制皮膚開啟的方法教程Win10
- VUE中setTimeout和setInterval自動銷燬Vue
- Python高階編專題 - 類的建立與銷燬Python
- 詳解.NET依賴注入中物件的建立與“銷燬”依賴注入物件
- ubuntu中將皮膚自動隱藏Ubuntu
- Service銷燬流程
- iOS單利的銷燬iOS
- 22_物件的銷燬物件
- win10控制皮膚快捷鍵是什麼 快速開啟控制皮膚的具體方法Win10
- 為什麼開啟控制皮膚會閃退 win10控制皮膚閃退的方法Win10
- Win10系統如何開啟控制皮膚 win10開啟控制皮膚的方法Win10
- 《effective java》讀書筆記1(建立和銷燬物件)Java筆記物件
- Java高效程式設計之一【建立和銷燬物件】Java程式設計物件
- 小喬皮膚
- 生命週期就是指物件的建立到銷燬的期間物件
- WebSphere Portal 7.0的主題與皮膚部署方法Web
- 自助控制皮膚模式配置SSL證書的方法模式
- win10撥出控制皮膚方法 win10怎麼撥出控制皮膚Win10
- win10 如何禁用前皮膚插孔檢測 win10禁用前皮膚方法Win10
- win10怎麼快速開啟控制皮膚 win10快速開啟控制皮膚的方法Win10
- iOS 建立一個在退出登入時可以銷燬的單例iOS單例
- php完全銷燬sessionPHPSession
- Spring Prototype Bean手動銷燬4種方法SpringBean
- 部落格園皮膚-我的部落格園皮膚設定教程
- win10控制皮膚怎麼顯示在桌面 win10桌面顯示控制皮膚的方法Win10
- Qt 編譯qt-material-widgets皮膚的方法QT編譯
- Axure之使用動態皮膚建立banner輪播圖
- 部落格皮膚