A Tkinter to wxPython Conversion
Robert Ramsdell
Great Lakes Dredge & Dock Company
wxPython
- Simple download for windows, not quite as simple for Linux.
- Based on the wxWidgets C++ class library (wxWindgets.org)
- Documentation of wxPython can be found in the wiki: wiki.wxpython.org
- The documentation provided with the package is the C++ documentation with a few python notes
- NB Despite what the wiki says, use import wx rather than import wxPython.wx
SimpleInput - My test bed
- Developed for one of my projects
- The idea was to provide a generic form that can make changes to various classes
- The SimpleInput is a panel or frame that is meant to be displayed on another window
Tkinter versus wx - Validating
def inputCheck(self, event=None):
wxPython: Validator
class SIValidator(wx.PyValidator):
Tkinter versus wx - The application
F = Tkinter.Tk()
F.title("Test SimpleInput")
wxPython: PySimpleApp & Frame
app = wx.PySimpleApp()
F = wx.Frame(None, -1, 'Test SimpleInput_wx')
Tkinter versus wx - Frame or Panel
class SimpleInput(Tkinter.Frame):
wxPython: Panel
class SimpleInput(wx.Panel):
Tkinter versus wx - Labels
L = Tkinter.Label(self, text=s)
wxPython: StaticText
L = wx.StaticText(self, -1, s)
Tkinter versus wx - Entry Boxes
e = Tkinter.Entry(self, width=8, justify=Tkinter.RIGHT)
wxPython: TextCtrl
e = wx.TextCtrl(self, -1, style=textCtrlStyle,
validator=eValidator)
Note the validator defined in the wxPython definition!
Tkinter versus wx - Buttons
OK = Tkinter.Button(F, text='OK', command=OK_Clicked)
wxPython: Button
OK = wx.Button(F, -1, 'OK')
F.Bind(wx.EVT_BUTTON, OK_Clicked, OK)
Tkinter versus wx - Events
e.bind('< Return>', self.focusOK)
e.bind('< FocusOut>', self.inputCheck)
wxPython: .Bind
self.Bind(wx.EVT_TEXT_ENTER, self.focusOK, e)
wxPython.wx: EVT_...
EVT_BUTTON(self.buttons[-1], buttonIDs[i],
buttonCallbacks[i])
Tkinter versus wx - Geometry
- Tkinter: .grid, .pack, .place
e.grid(row=i, column=1)
wxPython: Gridsizer, BoxSizer
bs = wx.BoxSizer(wx.VERTICAL)
...
bs.Add(SI)
F.SetSizer(bs)
How do They Look
- Windows
|
How do They Look
- Linux
|