Use wxpython gui framework
version newer than wxpython2.8 Use wxpython tp build python GUI
Basic document structure:

  • My Program
    • Layout
      • app.py
      • mainFrame.py
    • Resources
    • lib
    • run.py

main entrance

“run.py”⇒ Note that you should write like this to make compiler know the file is the main entrance of the program:

if __name__=='__main__':
Create wx.app object. Initiate other classes(suggested) and enter MainLoop of the program.
import app
import Class
if __name__=='__main__':
    thisClass = Class.init()
    ...
    thisapp = app.App(...)
    thisapp.MainLoop()
 

Class overwrite : app

“app.py”⇒Do not forget to import module wx .Two functions that must be overloaded:

import wx
import mainFrame
class App(wx.App):
    def __init__(self,redirect=False,...):
        ...
        wx.App.__init__(self,redirect,self.redirectFile,...)
 
    def OnInit(self):
        mainFrame = mainframe(parent=None,name='myprogram',...)
        mainFrame.Show(True)
        self.SetTopWindow(mainFrame)   # Set top window of this app, do not forget it!
        ... # initiate parameters or load configurations here
        return True

Class overwrite: Main Frame

“mainFrame.py”⇒The main frame that used to initiate your app. This is the basic frame of our program which must exits. You can put menus, panels and all other controls/windows in it.

import wx
from panel1 import p1
from panel2 import p2
import ...
 
class mainFrame(wx.Frame):  # overwrite original class "wx.Frame"
    def __init__(self,parent,...):
        wx.Frame.__init__(self,parent,-1,name,style=wx.DEFAULT_FRAME_STYLE & ~(wx.RESIZE_BORDER & wx.MAXIMIZE_BOX))
        self.setMenu()
        self.panel_1 = p1(self,-1,...)
        self.panel_2 = p2(self,-1,...)
 
    def setMenu(self):
        menuBar = wx.MenuBar()
        startmenu = wx.Menu()
        self.open = startmenu.Append(wx.ID_ANY,'O&pen')  # append menu selections to menu and return menu items
        startmenu.AppendSeparator()
        self.quit = startmenu.Append(wx.ID_EXIT,'&Quit')
        menuBar.Append(startmenu,'&Start')           # append menu to menubar
        self.Bind(wx.EVT_MENU,self.OnOpen,self.open)     # bind event handler to menu item
        self.Bind(wx.EVT_MENU,self.OnExit,quit)
        self.Bind(wx.EVT_RIGHT_UP,self.OnRightClick)
        self.SetMenuBar(menuBar)
 
    # Other functions and event handlers.
    ...

Event Handlers

Richard Feynman

“everything that is living can be understood in terms of the jiggling and wiggling of atoms”.

and now, we want to watch atoms jiggling and wiggling.

X-rays, electrons, fluorescence light, the advances of photon sciences, together with computational modeling, are making this happen.