views:

297

answers:

1

I need to create what I think should be a simple GUI. I have very little experience with building GUI's. I'm a visual learner and 'wxPython In Action' isn't helping me out. I don't learn well by books written by Ph.D.'s. I'm using Python 2.6. Many of the examples on the Internet don't work in Python 2.6.

I need to create a GUI with 3 columns and some buttons on the bottom.

On the first pass, each of the columns will be just multi-line text input. I've creating a GUI that did have 3 columns using 3 panels but I couldn't get the multi-line text input to fill the entire panel. I tried with boxsizer and flexgridsizer with one panel but again, I couldn't get the multi-line text input to fill the entire column.

Somewhere, I saw an example of almost exactly what I was looking for but I either didn't bookmark it or it was in an example and I forget where it is. This example had 3 columns where each of the columns could be width adjusted like in a spreadsheet.

I've been at this for quite a few days and I haven't made any progress. What I'm looking for is something akin to a Sashwindow but with 3 columns.

I've tried multiple panels, boxsizers with flexgridsizers but no luck. I've gone through all of the wxPython demos and nothing comes closs. Perhaps because what I looking for is too simple and not worthy of a demo. Some of the columns in the real program will use selectable lists and grids but first I need to start with the simplistic possible case.

Can anyone provide a minimalistic program that shows 3 columns with multi-line text input filling the entire column? I'll figure out how to add the buttons on the bottom.

Thank you,

+1  A: 

You should take a look at wxGlade. It's a handy little GUI builder you can use to create your UI. After that, you can also look at the code it generates and go from there.

Edit: Okay, here goes:

In wxGlade, create a new frame. Add a horizontal sizer with three slots. Add a TextCtrl to the first slot. On the Layout page for the text control, check wxEXPAND and set Proportion to 1; on the Widget page, check wxTE_MULTILINE. Copy the text control to the clipboard and paste into into the two remaining slots.

Here's the code that wxGlade generates:

#!/usr/bin/env python
# -*- coding: iso-8859-15 -*-
# generated by wxGlade 0.6.3 on Tue Jul 21 20:00:54 2009

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.text_ctrl_1 = wx.TextCtrl(self, -1, "", style=wx.TE_MULTILINE)
        self.text_ctrl_1_copy = wx.TextCtrl(self, -1, "", style=wx.TE_MULTILINE)
        self.text_ctrl_1_copy_1 = wx.TextCtrl(self, -1, "", style=wx.TE_MULTILINE)

        self.__set_properties()
        self.__do_layout()
        # end wxGlade

    def __set_properties(self):
        # begin wxGlade: MyFrame.__set_properties
        self.SetTitle("frame_1")
        # end wxGlade

    def __do_layout(self):
        # begin wxGlade: MyFrame.__do_layout
        sizer_1 = wx.BoxSizer(wx.VERTICAL)
        sizer_2 = wx.BoxSizer(wx.HORIZONTAL)
        sizer_2.Add(self.text_ctrl_1, 1, wx.EXPAND, 0)
        sizer_2.Add(self.text_ctrl_1_copy, 1, wx.EXPAND, 0)
        sizer_2.Add(self.text_ctrl_1_copy_1, 1, wx.EXPAND, 0)
        sizer_1.Add(sizer_2, 1, wx.EXPAND, 0)
        self.SetSizer(sizer_1)
        sizer_1.Fit(self)
        self.Layout()
        # end wxGlade

# end of class MyFrame


if __name__ == "__main__":
    app = wx.PySimpleApp(0)
    wx.InitAllImageHandlers()
    frame_1 = MyFrame(None, -1, "")
    app.SetTopWindow(frame_1)
    frame_1.Show()
    app.MainLoop()

Hope that helps :-)

balpha
I've been using Boa Constructor. Like wxGlade, it's useful only if you already know what you're doing. I've gone through the tutorials on ShowMeDo on wxPython and Boa Constructor (esp. video #8 multiple times). I wouldn't have asked if I hadn't already tried everything at my disposal.
Okay, I have edited my answer.
balpha
Sorry for not getting back sooner. I've been programming like made since you posted your code. Your solution was absolutely perfect. THANK YOU VERY MUCH. Once I got over that initial mental-lock hurdle, I was able to figure everything else out. I also gave wxGlade another chance and I've switched from Boa to wxGlade. I like the way wxGlade produces nearly hand-written code.My program does much more than have TextCtrls but I wanted to see the simplest possible case since I knew I could figure out the gory details on my own.
I couldn't vote on your solution since I don't have a 15 reputation. Stupid control freaks. I wanted to give you the max positive.
That's fine, glad I could help. Also, believe me from experience, the rep limits are a good thing in the average case. Cheers!
balpha