jeudi 19 mars 2015

button not work when i used wx.SplittedWindow


I create two windows in the frame by using wx.SplitterWindow, when I create a close button, this button does not ever work. Though I write code commonly in use.



ttp = wx.Button(panelOne, -1, 'Cancel', size=(90, 28), pos=(120, 280))
self.Bind(wx.EVT_BUTTON, self.OnClose, ttp)

def OnClose(self, event):
self.Close(True)


The full code I created



#!python
# -*- coding: utf-8 -*-


import sys
import wx

class MainFrame(wx.Frame):
""""""

#----------------------------------------------------------------------
def __init__(self):
"""Constructor"""
wx.Frame.__init__(self, None, title="Nested Splitters",
size=(1000,400))
panel = MainPanel(self)
self.Show()

class RandomPanel(wx.Panel):
""""""

#----------------------------------------------------------------------
def __init__(self, parent, color):
"""Constructor"""
wx.Panel.__init__(self, parent)
self.SetBackgroundColour(color)

class MainPanel(wx.Panel):
""""""

#----------------------------------------------------------------------
def __init__(self, parent):
"""Constructor"""
wx.Panel.__init__(self, parent)

topSplitter = wx.SplitterWindow(self)
vSplitter = wx.SplitterWindow(topSplitter)

panelOne = RandomPanel(topSplitter, "grey")
text1 = wx.StaticText(panelOne, -1, 'You', pos=(10, 4))
self.txt = wx.TextCtrl(panelOne, -1, size=(200, 20), pos=(10, 20))
text2 = wx.StaticText(panelOne, -1, 'Scarlett', pos=(10, 45))
self.klm = wx.TextCtrl(panelOne, -1, size=(200, 200), pos=(10, 65))

panelTwo = RandomPanel(topSplitter, "red")
self.txt = wx.TextCtrl(panelTwo, -1, size=(200, 100))
topSplitter.SplitVertically(panelOne, panelTwo)
topSplitter.SetSashGravity(0.5)

entr = wx.Button(panelOne, -1, 'Ok', size=(90, 28), pos=(10, 280))
ttp = wx.Button(panelOne, -1, 'Cancel', size=(90, 28), pos=(120, 280))

self.Bind(wx.EVT_BUTTON, self.OnClose, ttp)
#self.Bind(wx.EVT_BUTTON, self.OnEnter, entr)

#panelThree = RandomPanel(topSplitter, "green")
#topSplitter.SplitVertically(vSplitter, panelThree)
#topSplitter.SetSashGravity(0.5)

sizer = wx.BoxSizer(wx.VERTICAL)
sizer.Add(topSplitter, 1, wx.EXPAND)
self.SetSizer(sizer)

self.Center()
self.Show(True)

def OnClose(self, event):
self.Close(True)

# def OnEnter(self, event):
# self.result.SetLabel(self.PatMatch())

#----------------------------------------------------------------------

if __name__ == "__main__":
app = wx.App(False)
frame = MainFrame()
app.MainLoop()




Aucun commentaire:

Enregistrer un commentaire