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- 2 2147
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
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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Donald 'Paddy' McCarthy |
last post by:
Hi,
I am having a few problems with a GUI. I am new to traits and wxGlade.
I have used wxGlade to create a Form with an embedded space for a
CustomWidget.
I have the traits demo and would like...
|
by: Somesh Bartakkay |
last post by:
i installed wxGlade on System xp, when i started it ..its not running ?
|
by: LenS |
last post by:
I have installed wxGlade on a MS XP machine. It executed on completion
of the install. However, when I try to double click on the wxGlade
icon to start nothing happens. I searched the NG and...
|
by: physci |
last post by:
I've been combing google for the past week trying to find an
appropriate set of tools for a project I'm working on. Simply put,
what I need is a GUI, powered by python, (I really don't want to...
|
by: diffuser78 |
last post by:
I recently tried a hand at wxGlade and was happy to see it designs a
GUI for you in minutes. I am a newbie Python coder. I am not completely
aware of GUI programming.
I can easily make menubars...
|
by: crystalattice |
last post by:
I'm making a GUI for a console-based program I just wrote. I figured
it would be mostly straight forward to convert it over in wxPython but
now I'm confused.
In my console program, I have...
|
by: agsupriya86 |
last post by:
How to add keyboard event to a button in wxglade??
|
by: Steve Holden |
last post by:
I've been trying to use wxGlade recently and I am finding it something
of a challenge. Is there any user who finds the user interface
satisfactory and the operation of the program predictable?
...
|
by: exodus |
last post by:
As a fun little task to gain more knowledge of python, i decided to try to mimick the ipod UI with it. here's what i've got so far
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# generated by...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |