wx.MainFrame mit wx.MiniFrame "verknuepfen"
Verfasst: Samstag 22. Dezember 2007, 01:33
Hallo,
Hier erstmal der kurze Beispiel-Code:
Das Problem ist im def PlusEins(). Ich will eine "Verknuepfung" zwischen dem Button self.toggleButton3 im MainFrame und der def update() im MiniFrame machen. Es ist sicherlich Trivial, ich komme nur nicht Drauf.
Danke!
Mit freundlichen Gruessen,
Aleksandar
Hier erstmal der kurze Beispiel-Code:
Code: Alles auswählen
import wx
#---------------------------------------------------------------------------
class MyMiniFrame(wx.MiniFrame):
def __init__(self, parent, title, pos=wx.DefaultPosition, size=wx.DefaultSize,style=wx.DEFAULT_FRAME_STYLE):
wx.MiniFrame.__init__(self, parent, -1, title, pos, size, style)
StaticText8 = wx.StaticText(self, label='N:', name='staticText2', pos=wx.Point(2, 2), size=wx.Size(23, 13), style=0)
self.Bind(wx.EVT_CLOSE, self.OnCloseWindow)
self.textCtrl = wx.TextCtrl(self, name='nummer', pos=wx.Point(30, 15), size=wx.Size(70, 17), value='0')
def update(self):
n=int(self.textCtrl.GetValue())
self.textCtrl.Clear()
self.textCtrl.SetValue(n+1)
def OnCloseWindow(self, event):
print "OnCloseWindow"
self.Destroy()
#---------------------------------------------------------------------------
class MyFrame(wx.Frame):
def __init__(self, parent = None, id = -1, title = "", size = wx.Size(280, 120)):
wx.Frame.__init__(self, parent, id, title= '', pos = wx.Point(0, 0), size = size)
self.toggleButton2 = wx.ToggleButton(self, label='Miniframe', name='toggleButton2', pos=wx.Point(10, 10), size=wx.Size(90, 30), style=0)
self.toggleButton2.Bind(wx.EVT_TOGGLEBUTTON, self.OnButton)
self.toggleButton3 = wx.ToggleButton(self, label='+1', name='toggleButton2', pos=wx.Point(140, 10), size=wx.Size(90, 30), style=0)
self.toggleButton3.Bind(wx.EVT_TOGGLEBUTTON, self.PlusEins)
#############################################
#Hier (in PlusEins) liegt das Problem
def PlusEins(self, event):
self.ref = MyMiniFrame(self)
self.parent.update(self)
def OnButton(self, evt):
win = MyMiniFrame(self, "This is a wx.MiniFrame", style=wx.DEFAULT_FRAME_STYLE | wx.TINY_CAPTION_HORIZ)
win.SetSize((200, 200))
win.CenterOnParent(wx.BOTH)
win.Show(True)
def main():
app = wx.PySimpleApp()
myframe = MyFrame()
#myframe.Center()
myframe.Show()
app.MainLoop()
if __name__ == "__main__":
main()
Danke!
Mit freundlichen Gruessen,
Aleksandar