crating a simple GUI

Hello

The code bellow (and attached) intends to create a frame containing a
grid with 4 buttons (which events have'nt been implemented yet) and a "close"
button. I wonder what is missing to get this working, though I've been
reading the docs. I chose wxPython
as mi python program's GUI tool because its accessible for my screen reader, since I'm visualy impaired
and should build layouts by deducting how it will look like. Beyond, my
close button doesn't work, but according to what I got from docs, it
should be right. I'd thank very much for any help! Regards,

Sarah Barreto Marques

import wx

class mainWindow:
    def __init__(self, *args, **kwargs):
        wx.Frame.__init__(self, *args, **kwargs)
        self.sizer=wx.GridSizer(rows=2, cols=2, hgap=10, vgap=10)
        self.panel=wx.Panel(self)
        self.btTeste1=wx.Button(self.panel, -1, "teste 1")
        self.btTeste2=wx.Button(self.panel, -1, "teste 2")
        self.btTeste3=wx.Button(self.panel, -1, "teste 3")
        self.btTeste4=wx.Button(self.panel, -1, "teste 4")
        self.btClose=wx.Button(self.panel, wx.ID_CLOSE, "close")
        self.btClose.Bind(wx.EVT_BUTTON, self.OnClose)

        buttons=[self.btTeste1, self.btTeste2, self.btTeste3, self.btTeste4]
        for i in botoes:
            self.sizer.Add(i, 0, wx.EXPAND)

        self.Show(True)

    def OnClose():
        self.Close(True)

app=wx.App(False)
frame=mainWindow(None, title="cognitive tests")
app.MainLoop()
Sarah Barreto Marques

Núcleo de Pesquisa em Sistemas de Informação - NSI/IF Fluminense
Napnee - IF Fluminense

www.audiogames.com.br

@sarahbmarques

wx.py (909 Bytes)

One immediate problem is that you are not adding your close button
to the sizer - I would also suggest adding a keyboard shortcut to
each of your buttons as these can be a major advantage to the
visually impaired and to anybody working with a tracker pad. This
can be done in wxWidgets simply by adding to the text for the
button.

···

On 18/02/13 00:36, Sarah Marques wrote:


Hello
The code bellow (and attached) intends to create a frame containing a
grid with 4 buttons (which events have'nt been implemented yet) and a "close"
button. I wonder what is missing to get this working, though I've been
reading the docs. I chose wxPython
as mi python program's GUI tool because its accessible for my screen reader, since I'm visualy impaired
and should build layouts by deducting how it will look like. Beyond, my
close button doesn't work, but according to what I got from docs, it
should be right. I'd thank very much for any help! Regards,
Sarah Barreto Marques
import wx
class mainWindow:
def __init__(self, *args, **kwargs):
wx.Frame.__init__(self, *args, **kwargs)
self.sizer=wx.GridSizer(rows=2, cols=2, hgap=10, vgap=10)
self.panel=wx.Panel(self)
self.btTeste1=wx.Button(self.panel, -1, "teste 1")
self.btTeste2=wx.Button(self.panel, -1, "teste 2")
self.btTeste3=wx.Button(self.panel, -1, "teste 3")
self.btTeste4=wx.Button(self.panel, -1, "teste 4")
self.btClose=wx.Button(self.panel, wx.ID_CLOSE, "close")
self.btClose.Bind(wx.EVT_BUTTON, self.OnClose)
buttons=[self.btTeste1, self.btTeste2, self.btTeste3, self.btTeste4]
for i in botoes:
self.sizer.Add(i, 0, wx.EXPAND)
self.Show(True)
def OnClose():
self.Close(True)
app=wx.App(False)
frame=mainWindow(None, title="cognitive tests")
app.MainLoop()
Sarah Barreto Marques
Núcleo de Pesquisa em Sistemas de Informação - NSI/IF Fluminense
Napnee - IF Fluminense
@sarahbmarques


Steve Gadget Barnes

www.audiogames.com.br

Sarah,
It is a very good idea to get into the habit of putting everything
into sizers ASAP if you need the close button not to be part of the
grid of buttons then a top level sizer with the close button and the
grid sizer attached it a good way to go. You might also need to add
a self.Destroy() to the OnClose method and a sys.exit(0) after the
app.MainLoop(), (you will need to import sys for this to work).
It is a common practice in this newsgroup, as with quite a lot of
others, to bottom post so that any one email reads like a story
although sometimes you will find long posts that have been commented
at the points that they occur. Hope that this makes sense through
your screen reader.
Steve

···

On 18/02/13 13:51, Sarah Marques wrote:

The close button is not suposed to make part of the gridSizer. (Or
should I add a wxSizer to the panel and the gridSizer inside it?) Yes, I
intend to create these shortcuts, they are quite helpful, but I need
buttons to be displayed, first. I can navigate through them all with
screen reader, though they're not shown on screen.
-----Mensagem original-----
De: Steve Barnes Para: Data: Segunda, 18 de Fevereiro de 2013 06:13
Assunto: Re: [wxPython-users] crating a simple GUI


Steve Gadget Barnes

gadgetsteve@live.co.ukwxpython-users@googlegroups.com

Hi,
there are actually only few changes needed to make your sample code run,
check the attached file, to see, or adapt it to the intended form.

Basically, you probably wanted to inherit mainWindow form wx.Frame, i.e.:
mainWindow(wx.Frame): ...

the typo in: for i in botoes
could be corrected to:
for i in buttons: ...

Furthermore, the sizer has to be assigned to the respective panel:
self.panel.SetSizer(self.sizer)

in the signature of the OnClose method the class - self - and the
event - (produced on clicking the buttons in this case) need to be
added, e.g.

OnClose(self, evt):

In this basic sample, I just added the close button to the grid after
increasing the column count - you would probably want a more usual
layout with multiple sizers combined.

hth,
   vbr

wx_test_simple_gui.py (1020 Bytes)

···

2013/2/18 Sarah Marques <sarahbmarques@gmail.com>:

Hello

The code bellow (and attached) intends to create a frame containing a
grid with 4 buttons (which events have'nt been implemented yet) and a "close"
button. I wonder what is missing to get this working, though I've been
reading the docs. I chose wxPython
as mi python program's GUI tool because its accessible for my screen reader, since I'm visualy impaired
and should build layouts by deducting how it will look like. Beyond, my
close button doesn't work, but according to what I got from docs, it
should be right. I'd thank very much for any help! Regards,

Sarah Barreto Marques

import wx

class mainWindow:
    def __init__(self, *args, **kwargs):
        wx.Frame.__init__(self, *args, **kwargs)
        self.sizer=wx.GridSizer(rows=2, cols=2, hgap=10, vgap=10)
        self.panel=wx.Panel(self)
        self.btTeste1=wx.Button(self.panel, -1, "teste 1")
        self.btTeste2=wx.Button(self.panel, -1, "teste 2")
        self.btTeste3=wx.Button(self.panel, -1, "teste 3")
        self.btTeste4=wx.Button(self.panel, -1, "teste 4")
        self.btClose=wx.Button(self.panel, wx.ID_CLOSE, "close")
        self.btClose.Bind(wx.EVT_BUTTON, self.OnClose)

        buttons=[self.btTeste1, self.btTeste2, self.btTeste3, self.btTeste4]
        for i in botoes:
            self.sizer.Add(i, 0, wx.EXPAND)

        self.Show(True)

    def OnClose():
        self.Close(True)

app=wx.App(False)
frame=mainWindow(None, title="cognitive tests")
app.MainLoop()
Sarah Barreto Marques

Núcleo de Pesquisa em Sistemas de Informação - NSI/IF Fluminense
Napnee - IF Fluminense

www.audiogames.com.br

@sarahbmarques

--
You received this message because you are subscribed to the Google Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to wxpython-users+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Hi Sarah,

The close button is not suposed to make part of the gridSizer. (Or
should I add a wxSizer to the panel and the gridSizer inside it?) Yes, I
intend to create these shortcuts, they are quite helpful, but I need
buttons to be displayed, first. I can navigate through them all with
screen reader, though they're not shown on screen.

Welcome to the wonderful world of wxPython:-) .

Attached is an alternative way to create layouts using the wx.lib.sized_controls, I have become a fan of them over the last couple of years as they get the sizer stuff out of your way, and in addition you get platform compliant spacing.

The sized_controls most of the times do the "right" thing, but if you need something else they allow you to do that too.

Hope this is useful.

Werner

buttonlayout.py (1 KB)

···

On 18/02/2013 14:51, Sarah Marques wrote: