wxPython的Refresh與事件雙重響應


#!/usr/bin/env python

import wx

class DoubleEventFrame(wx.Frame):

    def __init__(self, parent, id):
        wx.Frame.__init__(self, parent, id, 'Frame With Button',
                size=(300, 100))
        self.panel = wx.Panel(self, -1)
    self.cc = 1
        self.button = wx.Button(self.panel, -1, "Click Me", pos=(100, 15))
        self.Bind(wx.EVT_BUTTON, self.OnButtonClick, self.button)
        self.button.Bind(wx.EVT_LEFT_DOWN, self.OnMouseDown)

    def OnButtonClick(self, event):
    if self.cc == 1:
            self.panel.SetBackgroundColour('Green')
        self.cc = 2
    else:
            self.panel.SetBackgroundColour('RED')
        self.cc = 1
        self.panel.Refresh() # 這里不管self.Refresh(),只要是parent,或者parent的parent進行Refresh()都可以

    def OnMouseDown(self, event):
        self.button.SetLabel("Again!")
        event.Skip() # 這里,處理完消息以后,還可以繼續傳遞同一條消息繼續處理。

if __name__ == '__main__':
    app = wx.PySimpleApp()
    frame = DoubleEventFrame(parent=None, id=-1)
    frame.Show()
    app.MainLoop()

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM