passing a tuple into a class function as a single argument

G

greywine

Hi everyone,

The following program doesn't work as expected:


#Python 2.7 & wxPython 2.9

import wx

class MyFrame(wx.Frame):
""" We simply derive a new class of Frame. """
def __init__(self, parent, title):
wx.Frame.__init__(self, parent, title=title, size=(200,100))
self.control = wx.TextCtrl(self, style=wx.TE_MULTILINE)
self.Show(True)

app = wx.App(False)
size=(600,400)
frame = MyFrame(None, 'Small editor')
#frame = MyFrame(None, 'Small editor', (600,400))
app.MainLoop()

If I use the default size=(200,100) it's just fine. But if I try it
pass it a new size (600,400), I get the following error:
Traceback (most recent call last):
File "C:\Python27\wxpythoneasy1.py", line 13, in <module>
frame = MyFrame(None, 'Small editor',((600,400)))
TypeError: __init__() takes exactly 3 arguments (4 given)

It seems like it's begging to have it pass a different size than the
default, but there doesn't seem to be a way to pass a tuple as a
single argument.

Any help would be appreciate.

Thanks,

John R.
 
M

Mel

Hi everyone,

The following program doesn't work as expected:


#Python 2.7 & wxPython 2.9

import wx

class MyFrame(wx.Frame):
""" We simply derive a new class of Frame. """
def __init__(self, parent, title):
wx.Frame.__init__(self, parent, title=title, size=(200,100))
self.control = wx.TextCtrl(self, style=wx.TE_MULTILINE)
self.Show(True)

app = wx.App(False)
size=(600,400)
frame = MyFrame(None, 'Small editor')
#frame = MyFrame(None, 'Small editor', (600,400))
app.MainLoop()

If I use the default size=(200,100) it's just fine. But if I try it
pass it a new size (600,400), I get the following error:
Traceback (most recent call last):
File "C:\Python27\wxpythoneasy1.py", line 13, in <module>
frame = MyFrame(None, 'Small editor',((600,400)))
TypeError: __init__() takes exactly 3 arguments (4 given)

It seems like it's begging to have it pass a different size than the
default, but there doesn't seem to be a way to pass a tuple as a
single argument.

Any help would be appreciate.

You have to tell __init__ what's coming.

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


and so on.

Mel.
 
D

Dennis Lee Bieber

(e-mail address removed) wrote:
You have to tell __init__ what's coming.

def __init__(self, parent, title, size):
wx.Frame.__init__(self, parent, title=title, size=size)
And if a default size is still wanted, it needs to be moved up a
level...

def __init__(self, parent, title, size=(200, 100)):
wx.Frame.__init__(self, parent, title=title, size=size)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,535
Members
45,007
Latest member
obedient dusk

Latest Threads

Top