I am working with python v2.7 and wxPython v3.0 on Windows 7 OS.
In my app I have a about menu. Upon clicking the about menu I want to display some information about my app. I am trying to create a dialog box/AboutBox exactly as shown in the image below.(This is the about dialog of notepad++. Click on ?
in the menu bar of notepad++.)
The special thing about the dialog box of notepad++ is that I need a text control window too. One can copy the info.
I tried to do the same in wxPython, but unfortunately I failed. I tried two different hit and trial approaches.
1. I tried to add the text control window to the dialog box wxMessageDialog but it doesn't shows up at all.
2. I tried to use the AboutBox in wxPython, and tried to add the text control to it but it failed because the AboutDialogInfo is not a window and the parent of the text control should be of a window type.
Error:
aboutPanel = wx.TextCtrl(info, -1, style = wx.TE_MULTILINE|wx.TE_READONLY|wx.HSCROLL)
File "C:\Python27\lib\site-packages\wx-3.0-msw\wx\_controls.py", line 2019, in __init__
_controls_.TextCtrl_swiginit(self,_controls_.new_TextCtrl(*args, **kwargs))
TypeError: in method 'new_TextCtrl', expected argument 1 of type 'wxWindow *'
It would be great if someone could provide some idea on how to add a text control windows to a dialog box/AboutBox?
Code: Here is my code sample for playing around:
import wx
from wx.lib.wordwrap import wordwrap
class gui(wx.Frame):
def __init__(self, parent, id, title):
wx.Frame.__init__(self,None, id, title, style=wx.DEFAULT_FRAME_STYLE)
panel1 = wx.Panel(self, -1)
panel1.SetBackgroundColour('#fffaaa')
menuBar = wx.MenuBar()
file = wx.Menu()
file.Append(101, '&About1', 'About1')
file.Append(102, '&About2', 'About2')
menuBar.Append(file, '&File')
self.SetMenuBar(menuBar)
wx.EVT_MENU(self, 101, self.onAbout)# Event for the About1 menu
wx.EVT_MENU(self, 102, self.onAboutDlg)# Event for the About2 menu
def onAbout(self, event):
message = 'This fantastic app was developed using wxPython.\nwxPython is c00l :)'
dlg = wx.MessageDialog(self, message, 'My APP', wx.OK|wx.ICON_INFORMATION)
aboutPanel = wx.TextCtrl(dlg, -1, style = wx.TE_MULTILINE|wx.TE_READONLY|wx.HSCROLL)
aboutPanel.WriteText('Experimentation is the part of our life.\n')
dlg.ShowModal()
dlg.Destroy()
def onAboutDlg(self, event):
self.panel = wx.Panel(self, -1)
info = wx.AboutDialogInfo()
info.Name = "My About Box"
info.Version = "0.1"
info.Copyright = "(C) 2014 xxx"
info.Description = wordwrap(
"This is an example application that shows the problem "
"that I am facing :)",
350, wx.ClientDC(self.panel))
info.WebSite = ("http://stackoverflow.com/users/2382792/pss", "My Home Page")
info.Developers = ["PSS"]
info.License = wordwrap("Driving license and a AK-47 too :P ", 500,wx.ClientDC(self.panel))
# Uncomment the following line to get the error!
#aboutPanel = wx.TextCtrl(info, -1, style = wx.TE_MULTILINE|wx.TE_READONLY|wx.HSCROLL)
#aboutPanel.WriteText('Experimentation is the part of our life.\n')
wx.AboutBox(info)
if __name__ == '__main__':
app = wx.App()
frame = gui(parent=None, id=-1, title="My-App")
frame.Show()
app.MainLoop()
Thank you for your time!