I don’t know C or C++ that much to develop GUI applications. I hate Java and I’m not really ready to type lines after lines to develop very simple applications. PHP and Python are the only available solutions to me. For PHP, I have PHP-GTK, WinBinder and some obsolete tools like wxPHP, php-tk and a few others. For Python, I have PyGTK, PyQT, Tk and wxPython. I have experimented with PHP-GTK, WinBinder, PyGTK, Tk and wxPython. In fact when I first tried to learn python around a year back, I first started with wxPython but ended up with nothing. Time has passed. I want to develop cross platform applications. So, I had to leave WinBinder which is Windows only. I don’t really like the idea of running Windows apps with Wine. I stuck to PHP-GTK for a while and tried PyGTK too. I liked Tk as well. With Windows installation of Python, they ship Tk. But it was not a very rich tool to develop complex GUI applications. While I liked PHP-GTK, I had to admit PHP is not really suitable for developing desktop GUI apps. I loved the flexibility and strength of Python. I experimented with both PyGTK and wxPython. I didn’t try PyQT though. I use Ubuntu (Gnome) and don’t like KDE much.
Among these two, I will definitely go for wxPython. Because applications developed with wxPython is very easy to deploy on both Windows and Linux. And it’s really very easy to finish the layout using the wxGlade tool. wxGlade generates the skeleton Python code in a beautiful way. It defines all the event handlers as well. The code is very well structured. It subclasses the wx.Frame class and defines specific methods for setting the different properties and laying the widgets out. So, if you ever need to tweak the GUI a bit, you’ll know where to find what 🙂
Here’s the source code of a tabbed application I built in just 5 minutes. It has a “Home” button. When you click the button, it opens a new browser and takes you to my website.
I wrote only two lines of code.
1 2 |
import webbrowser webbrowser.open_new_tab("https://masnun.com") |
Here is the full source code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
#!/usr/bin/env python # -*- coding: utf-8 -*- # generated by wxGlade 0.6.3 on Wed Apr 28 13:14:15 2010 import wx # begin wxGlade: extracode # end wxGlade class MyFrame(wx.Frame): def __init__(self, *args, **kwds): # begin wxGlade: MyFrame.__init__ kwds["style"] = wx.DEFAULT_FRAME_STYLE wx.Frame.__init__(self, *args, **kwds) self.Notebook = wx.Notebook(self, -1, style=wx.NB_BOTTOM) self.Notebook_Home = wx.Panel(self.Notebook, -1) self.panel_1 = wx.Panel(self.Notebook_Home, -1) self.panel_2 = wx.Panel(self.Notebook_Home, -1) self.panel_3 = wx.Panel(self.Notebook_Home, -1) self.panel_15 = wx.Panel(self.Notebook_Home, -1) self.panel_20 = wx.Panel(self.Notebook_Home, -1) self.panel_4 = wx.Panel(self.Notebook_Home, -1) self.panel_8 = wx.Panel(self.Notebook_Home, -1) self.panel_12 = wx.Panel(self.Notebook_Home, -1) self.panel_16 = wx.Panel(self.Notebook_Home, -1) self.panel_21 = wx.Panel(self.Notebook_Home, -1) self.panel_5 = wx.Panel(self.Notebook_Home, -1) self.panel_9 = wx.Panel(self.Notebook_Home, -1) self.button_1 = wx.Button(self.Notebook_Home, -1, "Home") self.panel_17 = wx.Panel(self.Notebook_Home, -1) self.panel_22 = wx.Panel(self.Notebook_Home, -1) self.panel_6 = wx.Panel(self.Notebook_Home, -1) self.panel_10 = wx.Panel(self.Notebook_Home, -1) self.panel_13 = wx.Panel(self.Notebook_Home, -1) self.panel_18 = wx.Panel(self.Notebook_Home, -1) self.panel_23 = wx.Panel(self.Notebook_Home, -1) self.panel_7 = wx.Panel(self.Notebook_Home, -1) self.panel_11 = wx.Panel(self.Notebook_Home, -1) self.panel_14 = wx.Panel(self.Notebook_Home, -1) self.panel_19 = wx.Panel(self.Notebook_Home, -1) self.panel_24 = wx.Panel(self.Notebook_Home, -1) self.__set_properties() self.__do_layout() self.Bind(wx.EVT_BUTTON, self.onClick, self.button_1) # end wxGlade def __set_properties(self): # begin wxGlade: MyFrame.__set_properties self.SetTitle("My App") self.SetSize((434, 385)) self.SetFocus() # end wxGlade def __do_layout(self): # begin wxGlade: MyFrame.__do_layout MainGridSizer = wx.GridSizer(1, 1, 5, 5) grid_sizer_1 = wx.GridSizer(5, 5, 5, 5) grid_sizer_1.Add(self.panel_1, 1, wx.EXPAND, 0) grid_sizer_1.Add(self.panel_2, 1, wx.EXPAND, 0) grid_sizer_1.Add(self.panel_3, 1, wx.EXPAND, 0) grid_sizer_1.Add(self.panel_15, 1, wx.EXPAND, 0) grid_sizer_1.Add(self.panel_20, 1, wx.EXPAND, 0) grid_sizer_1.Add(self.panel_4, 1, wx.EXPAND, 0) grid_sizer_1.Add(self.panel_8, 1, wx.EXPAND, 0) grid_sizer_1.Add(self.panel_12, 1, wx.EXPAND, 0) grid_sizer_1.Add(self.panel_16, 1, wx.EXPAND, 0) grid_sizer_1.Add(self.panel_21, 1, wx.EXPAND, 0) grid_sizer_1.Add(self.panel_5, 1, wx.EXPAND, 0) grid_sizer_1.Add(self.panel_9, 1, wx.EXPAND, 0) grid_sizer_1.Add(self.button_1, 0, wx.ALIGN_CENTER_HORIZONTAL|wx.ALIGN_CENTER_VERTICAL, 0) grid_sizer_1.Add(self.panel_17, 1, wx.EXPAND, 0) grid_sizer_1.Add(self.panel_22, 1, wx.EXPAND, 0) grid_sizer_1.Add(self.panel_6, 1, wx.EXPAND, 0) grid_sizer_1.Add(self.panel_10, 1, wx.EXPAND, 0) grid_sizer_1.Add(self.panel_13, 1, wx.EXPAND, 0) grid_sizer_1.Add(self.panel_18, 1, wx.EXPAND, 0) grid_sizer_1.Add(self.panel_23, 1, wx.EXPAND, 0) grid_sizer_1.Add(self.panel_7, 1, wx.EXPAND, 0) grid_sizer_1.Add(self.panel_11, 1, wx.EXPAND, 0) grid_sizer_1.Add(self.panel_14, 1, wx.EXPAND, 0) grid_sizer_1.Add(self.panel_19, 1, wx.EXPAND, 0) grid_sizer_1.Add(self.panel_24, 1, wx.EXPAND, 0) self.Notebook_Home.SetSizer(grid_sizer_1) self.Notebook.AddPage(self.Notebook_Home, "Home") MainGridSizer.Add(self.Notebook, 1, wx.EXPAND, 0) self.SetSizer(MainGridSizer) self.Layout() # end wxGlade def onClick(self, event): # wxGlade: MyFrame.<event_handler> import webbrowser webbrowser.open_new_tab("https://masnun.com") # end of class MyFrame if __name__ == "__main__": app = wx.PySimpleApp(0) wx.InitAllImageHandlers() MainFrame = MyFrame(None, -1, "") app.SetTopWindow(MainFrame) MainFrame.Show() app.MainLoop() |
5 replies on “Quick GUI Development with wxPython and wxGlade”
Super cool. Planning to buy a book on python tomorrow 🙂
@Tushar:
You won’t get any good books on Python in BD AFAIK. Download “Think Python” as a PDF. It’s a good book!
Also join: http://pybangla.appspot.com 🙂
Thanks 🙂
please , is there a summary or catalog for python wx widgets method ?
some thing like : text_ctrl_1.get…..() or
Notebook.AddPage(…..)
i m a WX beginner and did all necessary design
but i can’t retrieve text control contents 🙂 ha ha ha …
forgive me if you don’t like coding qustions on your blog 😉
I have started using PyQT and recommend using that. I no longer use wxPython. So, I can not tell 😀