HomePython Page 2 - Designing a Calculator in wxPython
The Plan - Python
wxPython is a library that makes it easy for Python programmers to build graphical user interfaces. Over the past few weeks, you have seen some articles covering this library. This week, you will learn how to create a simple but useful application with wxPython.
The best way to organize our calculator is to use a wxGridBagSizer. Our buttons will almost be the same size and will be organized in rows and columns, so a wxGridBagSizer is perfect for the job. The wxGridBagSizer is also pretty simple to use, so that's another plus.
Our calculator isn't going to be very complex, as I mentioned before. On the first row of our calculator will be the display, which will be served by a read-only wxTextCtrl. The display will take up the entire row. The second row will contain the add to memory button, a button for the number one, a button for the number two, a button for the number three and an addition button. The third row will contain a delete from memory button, a button for the number four, a button for the number five, a button for the number six and a subtraction button. The fourth row will contain a memory recall button, a button for the number seven, a button for the number eight, a button for the number nine and a multiplication button. The fifth row will contain a wxStaticText that displays the number currently in memory, a decimal button, a zero button, a solve button and a division button. The final row will contain a two-column clear button, a backspace button, a positive/negative button and a square root button.
We'll save ourselves the pain of creating over a dozen methods by making use of event ID numbers. I'll show you how to do this once we're at that point.