Diferent files: GUI (wxpython) Program

cmpython at gmail.com cmpython at gmail.com
Fri Oct 12 06:12:06 CEST 2007

On Oct 11, 7:47 pm, marc <mar... at gmail.com> wrote:
> cmpyt... at gmail.com escribió:> On Oct 11, 5:44 pm, marc <mar... at gmail.com> wrote:
> >> Hi why I can call an .py GUI (wxpython) from a program and control it?
> >> I'm newbie in python.
> > Sorry, could you restate that?  Explain again what you want to do.
> I would to call a python file that contains a GUI (with wx) from a file
> program.
> The programs that I've do, contains a GUI and the code to run it in the
> same file, but I when need to modify a GUI file (I use wxglade) I need
> to delete all code lines (except the GUI code lines) and it difficult
> the program.


I haven't used wxGlade, but I would be surprised
if you would have to delete all the code lines in
order to modify the GUI part of the program,
but maybe I am misunderstanding something.  You
should ask on some wxGlade list or help file or

I use Boa Constructor to help build GUIs and it
allows you to make a file which will run the main
frame (the GUI itself).  Maybe this is what you are
looking for?  If so, this is one way to do it:

Say you have a main frame which is your GUI.  Here
is the code for that (this is simply a frame with
a panel on it, super simple):

#--------------MAIN FRAME---------------------------
import wx

def create(parent):
   return Frame1(parent)

class Frame1(wx.Frame):

    def __init__(self, parent):
        wx.Frame.__init__(self, id=-1, parent=parent)

        self.panel1 = wx.Panel(id=-1, parent=self)

You can save this as testFrame1.py

Now you have the program which calls this frame, which we can
save as testApp1.py.  The code for that is as follows:

#------------The app that calls the GUI-------------------
import wx
import testFrame1

class MyApp(wx.App):
    def OnInit(self):
        self.main = testFrame1.create(None)
        return True

def main():
    application = MyApp(0)

if __name__ == '__main__':

Now you can change anything in the file called
testFrame1 and still launch it from the file
called testApp1.  I think that's basically what
you wanted to do if I understood it.

I'd recommend checking out Boa Constructor.  I've
trimmed the auto-generated code from it to make
it simplified for this message, but it is good
once you're used to it, and it is very easy to make
quick changes to the GUI, both by coding or by using
its Designer, which allows you to arrange the GUI
elements visually.

Lastly, it is probably better to ask questions about
wxPython on the wxPython list.


More information about the Python-list mailing list