Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > wxGlade

Reply
Thread Tools

wxGlade

 
 
Pilu
Guest
Posts: n/a
 
      02-19-2004
hi,given that I'm a newbie in python,
I have a little problem with wx...
Maybe it's a stupid thing,but if u want help me!
I used wxglade to generate a simple window with a button!
wxglade generates the code,and now I try to insert events,but I have an
error,I don't understand!
The code is this:

from wxPython.wx import *

class MyFrame(wxFrame):
def __init__(self, *args, **kwds):
# begin wxGlade: MyFrame.__init__
kwds["style"] = wxDEFAULT_FRAME_STYLE
wxFrame.__init__(self, *args, **kwds)
self.button_1 = wxButton(self, -1, "button_1")

self.__set_properties()
self.__do_layout()
# end wxGlade
EVT_BUTTON(self, 1003, self.event)

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 = wxBoxSizer(wxVERTICAL)
sizer_1.Add(self.button_1, 0, 0, 0)
self.SetAutoLayout(1)
self.SetSizer(sizer_1)
sizer_1.Fit(self)
sizer_1.SetSizeHints(self)
self.Layout()
# end wxGlade
def event(self):
print "ciao"

# end of class MyFrame


class MyApp(wxApp):
def OnInit(self):
frame = MyFrame(NULL, -1, "Hello from wxPython")
frame.Show(true)
self.SetTopWindow(frame)
return true

app = MyApp(0)
app.MainLoop()





Thanks
-pilu-
 
Reply With Quote
 
 
 
 
Markus Faltin
Guest
Posts: n/a
 
      02-19-2004
I'm a newbie regarding wxPython, nevertheless I worked this out:

> class MyFrame(wxFrame):
> def __init__(self, *args, **kwds):
> # begin wxGlade: MyFrame.__init__
> kwds["style"] = wxDEFAULT_FRAME_STYLE
> wxFrame.__init__(self, *args, **kwds)
> self.button_1 = wxButton(self, -1, "button_1")
> self.__set_properties()
> self.__do_layout()
> # end wxGlade
> EVT_BUTTON(self, 1003, self.event)


You have to set the identifier of the button:
self.button_1 = wxButton(self, 1003, "button_1")

> def event(self):
> print "ciao"


The triggered method also needs the event as a parameter:

def event(self, event):
print "ciao"


Markus
 
Reply With Quote
 
 
 
 
Brian Kelley
Guest
Posts: n/a
 
      02-20-2004
Markus Faltin wrote:
> I'm a newbie regarding wxPython, nevertheless I worked this out:
>
>
>>class MyFrame(wxFrame):
>> def __init__(self, *args, **kwds):
>> # begin wxGlade: MyFrame.__init__
>> kwds["style"] = wxDEFAULT_FRAME_STYLE
>> wxFrame.__init__(self, *args, **kwds)
>> self.button_1 = wxButton(self, -1, "button_1")
>> self.__set_properties()
>> self.__do_layout()
>> # end wxGlade
>> EVT_BUTTON(self, 1003, self.event)

>
>
> You have to set the identifier of the button:
> self.button_1 = wxButton(self, 1003, "button_1")


Not necessarily, you can keep the -1 designation and then
EVT_BUTTON(self, self.button_1.GetId(), self.event)

I prefer this method since it is less book keeping for me.

Brian Kelley

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
ANN: SPE 0.7.2.A IDE with uml, wxGlade and blender support http://www.stani.be Python 0 02-06-2005 03:01 AM
ANN: SPE 0.7.2.A IDE with wxGlade, Uml & Blender support s_t_a_n_i@yahoo.com Python 0 02-05-2005 08:55 PM
RE: wxGlade not Running ! Delaney, Timothy C (Timothy) Python 1 03-02-2004 12:19 PM
wxGlade not Running ! Ben Finney Python 1 03-02-2004 04:32 AM
Help: GUI wxGlade/traits linkage Donald 'Paddy' McCarthy Python 1 10-19-2003 08:35 PM



Advertisments