python 2.7 - wxPython Buttons and Pop up Message -
i'm creating wxpython app lists rows of buttons. when buttons pressed, pop-up message (which quote) displayed. i'm having trouble programming buttons display pop message.
1) i'm having trouble having pop message displayed after wx.togglebutton clicked.
2) other problem how can make multiple buttons each display different message
import wx class mydialog(wx.dialog): def __init__(self, parent, id, title): wx.dialog.__init__(self, parent, id, title, size=(350,300)) class myframe(wx.frame): def __init__(self, parent, id, title): wx.frame.__init__(self, parent, id, title, size=(550,500)) self.createstatusbar() #creates statusbar in bottom filemenu = wx.menu() #about , exit menuabout = filemenu.append(wx.id_about, "&about", " information programme") menuexit = filemenu.append(wx.id_exit, "e&xit", " terminate programme") menubar = wx.menubar() menubar.append(filemenu, "&file") self.setmenubar(menubar) panel = wx.panel(self, -1) wx.togglebutton(panel, 1, 'quote1', (100,100)) self.bind(wx.evt_menu, self.onabout, menuabout) self.bind(wx.evt_menu, self.onexit, menuexit) def quote1(self, e): description = """message here""" def onabout(self, e): dlg = wx.messagedialog( self, "about here ") dlg.showmodal() dlg.destroy() def onexit(self, e): self.close(true) class myapp(wx.app): def oninit(self): frame = myframe(none, -1, 'customdialog1.py') frame.show(true) frame.centre() return true app = myapp(0) app.mainloop()
it's easy create series of buttons , bind them same handler. wrote on topic few years ago here. using example, created simple using example:
import wx class transientmessage(wx.popuptransientwindow): def __init__(self, parent, style, message): wx.popuptransientwindow.__init__(self, parent, style) text = wx.statictext(self, label=message) sz = text.getbestsize() self.setsize( (sz.width+20, sz.height+20)) class myframe(wx.frame): def __init__(self, parent, id, title): wx.frame.__init__(self, parent, id, title, size=(550,500)) self.createstatusbar() #creates statusbar in bottom filemenu = wx.menu() #about , exit menuabout = filemenu.append(wx.id_about, "&about", " information programme") menuexit = filemenu.append(wx.id_exit, "e&xit", " terminate programme") self.quotes = {'btn1': 'quote 1', 'btn2': 'another quote', 'btn3': 'fore score , 7 years ago'} menubar = wx.menubar() menubar.append(filemenu, "&file") self.setmenubar(menubar) panel = wx.panel(self, -1) topsizer = wx.boxsizer(wx.horizontal) btn in self.quotes: new_btn = wx.button(panel, label=btn, name=btn) topsizer.add(new_btn, 0, wx.all, 5) new_btn.bind(wx.evt_button, self.quote1) panel.setsizer(topsizer) self.bind(wx.evt_menu, self.onabout, menuabout) self.bind(wx.evt_menu, self.onexit, menuexit) def quote1(self, e): btn = e.geteventobject() quote = self.quotes[btn.getname()] win = transientmessage(self, wx.simple_border, quote) pos = btn.clienttoscreen( (0,0) ) sz = btn.getsize() win.position(pos, (0, sz[1])) win.popup() def onabout(self, e): dlg = wx.messagedialog( self, "about here ") dlg.showmodal() dlg.destroy() def onexit(self, e): self.close(true) class myapp(wx.app): def oninit(self): frame = myframe(none, -1, 'customdialog1.py') frame.show(true) frame.centre() return true app = myapp(0) app.mainloop()
you want change value of quote dictionary data structure contains label of button , quote instead of using same string button's label , name.
Comments
Post a Comment