

Now, time to add them to the layout manager. That's because we need to access it later, in other methods. Note that we keep a referece to this widget in our class: self.entry=. (For the text in Tkinter.Entry, we will see this later.) TextCtrl has 2 more parameters: -1 (so that wxPython automatically assigns an identifier.), and the text itself ( u'Enter text here.'). In both cases we pass self as parent parameter, because our window will be the parent of this widgets: They will appear in our window. In wxPython, we create TextCtrl object ( self.entry=wx.TextCtrl()) In Tkinter, we create the Entry widget ( self.entry=Tkinter.Entry()) Self.entry = wx.TextCtrl(self,-1,value=u"Enter text here.") In wxPython, we create the grid layout manager with sizer=wx.GridBagSizer() and then ask our window to use it ( self.SetSizerAndFit(sizer)). In Tkinter, calling id() will simply create the grid layout manager, and tell our window to use it. If you have to learn one, learn this one. Like you would place things in a spreadsheet (Excel, OpenOfficeįor example: Put a button at column 2, row 1. It's a simple grid where you put your widgets, just Some are more flexible than others.Įach container (window, pane, tab, dialog.) can have its own layout manager. So there are different classes (called layout managers) capable of placing the widgets in containers in different ways. There are several way to put widgets in a window (or anotherĬontainer): Add them side by site horizontally, vertically, in
#Easy weather python code code
Now close them, and let's get back to the code to add widgets. This is call event-driven programming (Because the program will do nothing but wait for events, and only react when it receives an event.)Īt this point, you can run both programs: They work ! The Tkinter and wxPython main loops will receive these events and handle them accordingly. It means that each program will now loop indefinitely, waiting for events (user clicking a button, pressing keys, operating system asking our application to quit, etc.). And we give our window a title: 'my application'. We use -1 to let wxPython choose an identifier itself. We also give it no parent ( None), because it's the first GUI element we build. Then we instanciate our class ( frame=simpleapp_wx()). In wxPyhon, it is mandatory to instanciate a wx.App() object before creating GUI elements.

We also give a title to our window ( app.title()). We give it no parent ( None), because it's the first GUI element we build. In Tkinter, we instanciate our class ( app=simpleapp_tk()).

We create a main which is executed when the program is run from the command-line. Wx.Frame object has two more parameters: id (an identifier of the widget) and title (the title of the window).įrame = simpleapp_wx(None,-1,'my application') Of widgets, repaint them on screen or simply destroy them when Keeping track of parents is usefull when we have to show/hide a group That's why both constructor have a parent parameter. So each GUI element has a parent (its container, usually). Which is contained in a tab which is contained in a window, etc. Simpleapp_wx inherits from wx.Frame, so we have to call the wx.Frame constructor ( wx.Frame._init_()).Ī GUI is a hierarchy of objects: A button may be contained in a pane Simpleapp_tk derives from Tkinter.Tk, so we have to call the Tkinter.Tk constructor ( Tkinter.Tk._init_()). Raise ImportError,"The wxPython module is required to run this program"

Our project is to create a very simple application like this:
