473,408 Members | 2,399 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

wxpython: how do i write this without the id parameter?

I was reading in the wxPython wiki that most of the time you don't have
to include the id parameter at all, and you can just use keyword
arguments for other parameters. But I'm having trouble converting this
code into that method (i.e., without the id parameter). I keep getting
errors that involve wrong parameters, or that they are out of order,
etc. So I'm hoping someone can show me how to re-write the constructors
for InputForm and wx.Frame, as well as the __init__ method, so that they
will just deal with parent and title.

Also, the two buttons have an id parameter, but leaving them out doesn't
seem to create any problems.

Thanks.

-----------

import wx
class InputForm(wx.Frame):

def __init__(self, parent, id, title):
wx.Frame.__init__(self, parent, id, title)

panel = wx.Panel(self)
self.btnOK = wx.Button(panel, label='OK')
self.btnCancel = wx.Button(panel, label='Cancel')

sizer = wx.BoxSizer(wx.HORIZONTAL)
sizer.Add(self.btnOK, 0, wx.ALL, 10)
sizer.Add(self.btnCancel, 0, wx.ALL, 10)
panel.SetSizer(sizer)
class MyApp(wx.App):

def OnInit(self):
frame = InputForm(None, -1, title='Data Entry Form')
self.SetTopWindow(frame)
frame.Show()
return True
app = MyApp(redirect=False)
app.MainLoop()
Jun 12 '06 #1
7 1807
Hi John
John Salerno a écrit :
I was reading in the wxPython wiki that most of the time you don't have
to include the id parameter at all, and you can just use keyword
arguments for other parameters. But I'm having trouble converting this
code into that method (i.e., without the id parameter). I keep getting
errors that involve wrong parameters, or that they are out of order,
etc. So I'm hoping someone can show me how to re-write the constructors
for InputForm and wx.Frame, as well as the __init__ method, so that they
will just deal with parent and title.


May I suggest you to use wx.ID_ANY each time you need an id.
It's a very clean way to give it even if you don't really care.
For instance :
wx.StaticBox(self,wx.ID_ANY,"etc...")

Regards,
jm
Jun 12 '06 #2
John Salerno wrote:
I was reading in the wxPython wiki that most of the time you don't have
to include the id parameter at all, and you can just use keyword
arguments for other parameters. But I'm having trouble converting this
code into that method (i.e., without the id parameter)....

import wx

class InputForm(wx.Frame):
def __init__(self, parent, id, title):
wx.Frame.__init__(self, parent, id, title)
panel = wx.Panel(self)
self.btnOK = wx.Button(panel, label='OK')
self.btnCancel = wx.Button(panel, label='Cancel')
sizer = wx.BoxSizer(wx.HORIZONTAL)
sizer.Add(self.btnOK, 0, wx.ALL, 10)
sizer.Add(self.btnCancel, 0, wx.ALL, 10)
panel.SetSizer(sizer)

class MyApp(wx.App):
def OnInit(self):
frame = InputForm(None, -1, title='Data Entry Form')
self.SetTopWindow(frame)
frame.Show()
return True

app = MyApp(redirect=False)
app.MainLoop()


import wx
__version__ = '0.0'

class InputForm(wx.Frame):
def __init__(self, parent=None, id=-1, title=__file__):
# or, if you prefer: ..., id=wx.ID_ANY, ...
wx.Frame.__init__(self, parent=parent, id=id,
title='%s v%s' % (title, __version__))
panel = wx.Panel(self)
sizer = wx.BoxSizer(wx.HORIZONTAL)
panel.SetSizer(sizer)
sizer.Add(wx.Button(panel, label='OK'), 0, wx.ALL, 10)
sizer.Add(wx.Button(panel, label='Cancel'), 0, wx.ALL, 10)

class MyApp(wx.App):
def OnInit(self):
frame = InputForm(title='Data Entry Form')
self.SetTopWindow(frame)
frame.Show()
return True

if __name__ == '__main__':
MyApp(redirect=False).MainLoop()
--Scott David Daniels
sc***********@acm.org
Jun 13 '06 #3
Scott David Daniels wrote:

class InputForm(wx.Frame):
def __init__(self, parent=None, id=-1, title=__file__):
# or, if you prefer: ..., id=wx.ID_ANY, ...
wx.Frame.__init__(self, parent=parent, id=id,
title='%s v%s' % (title, __version__)) class MyApp(wx.App):
def OnInit(self):
frame = InputForm(title='Data Entry Form')
self.SetTopWindow(frame)
frame.Show()
return True


Thanks, but there was an example (which I can't find now) somewhere in
the wxPython wiki that showed a call to wx.Frame without the id
parameter at all, like wx.Frame(parent, title). How is that possible?

Is the issue with my code just that I'm passing the parameters around
and so I can't be as concise as that?
Jun 13 '06 #4
Scott David Daniels wrote:
class InputForm(wx.Frame):
def __init__(self, parent=None, id=-1, title=__file__):


Also, is there a way to define parent and id with defaults, but not
title? Is it good to change the order around to do this?
Jun 13 '06 #5
Scott David Daniels wrote:
def __init__(self, parent=None, id=-1, title=__file__):


I get that __file__ is not defined.
Jun 13 '06 #6
John Salerno wrote:
Scott David Daniels wrote:
class InputForm(wx.Frame):
def __init__(self, parent=None, id=-1, title=__file__):


Also, is there a way to define parent and id with defaults, but not
title? Is it good to change the order around to do this?

No, too many things know the first couple of args are parent and id.
If __file__ doesn't work for you, just stick in something for title
and remember to replace it.

class InputForm(wx.Frame):
def __init__(self, parent=None, id=-1, title='Input Form"):

--Scott David Daniels
sc***********@acm.org
Jun 14 '06 #7
Scott David Daniels:
John Salerno wrote:
I was reading in the wxPython wiki that most of the time you don't have
to include the id parameter at all, and you can just use keyword
arguments for other parameters. But I'm having trouble converting this
code into that method (i.e., without the id parameter)....

import wx

class InputForm(wx.Frame):
def __init__(self, parent, id, title):
wx.Frame.__init__(self, parent, id, title)


I usually do it like this:

class InputForm(wx.Frame):
def __init__(self, *args, **kwargs):
super(InputForm, self).__init__(*args, **kwargs)
...

Cheers, Frank
Jun 17 '06 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Tom Plunket | last post by:
(Is this an appropriate place to ask wxPython questions?) Here's some code (line breaks put in without testing them, I'm kinda a newbie hope they're ok): <busted.py> from wxPython.wx import...
15
by: Grant Edwards | last post by:
Can anybody recommend a good book on wxPython? Are there any books on wxPython? I've been trying to learn wxPython and/or wax for a few weeks, and I'm just not getting it. wxWindows seems...
6
by: Batista, Facundo | last post by:
I'm still deciding about using Tkinter or wxPython for a project I have (sigefi, on SF). The decision is not made, I have to finish first a little program that will be done in both GUIs, and...
22
by: dcrespo | last post by:
Hi all... I think wxPython is much better than PyGTK. First of all, PyGTK needs the GTK runtime installed, whereas wxPython is entirely Python's modules, so It facilitates the apps'...
14
by: Rod W | last post by:
I'm just starting out on Python but my primary goal is to provide applications with some user interface (GUI). Can someone point me to a good comparison of whether I should use wxPython (with...
12
by: vivainio | last post by:
I rarely do GUIs, and reminded myself today why that is the case (simply, it's not fun). I implemented a simple TreeCtrl, and had to implement my own 'children' method, of all things! Here it...
44
by: bg_ie | last post by:
Hi, I'm in the process of writing some code and noticed a strange problem while doing so. I'm working with PythonWin 210 built for Python 2.5. I noticed the problem for the last py file...
1
by: [david] | last post by:
What am I doing wrong? I'm trying to capture stdErr in a multi-threaded program. This code crashes wxPython with /Py Assertion Error: C++ assertion "m_count=-1 || m_count=-2" failed/ What I'm...
16
by: Andrea Gavana | last post by:
Hi Diez & All, Do you mind explaining "why" you find it *buttugly*? I am asking just out of curiosity, obviously. I am so biased towards wxPython that I won't make any comment on this thread...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
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
0
BarryA
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
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,...
0
jinu1996
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.