Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1006041
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T08:23:45+00:00 2026-05-16T08:23:45+00:00

okay code: #!/usr/bin/python import wx import sys class XPinst(wx.App): def __init__(self, redirect=False, filename=None): wx.App.__init__(self,

  • 0

okay code:

#!/usr/bin/python

import wx
import sys

class XPinst(wx.App):
    def __init__(self, redirect=False, filename=None):
        wx.App.__init__(self, redirect, filename)
    def OnInit(self):
        frame = wx.Frame(None, -1, title='Redirect Test', size=(620,450), style=wx.STAY_ON_TOP|wx.DEFAULT_FRAME_STYLE)
        panel = wx.Panel(frame, -1)
        log = wx.TextCtrl(panel, -1, size=(500,400), style = wx.TE_MULTILINE|wx.TE_READONLY|wx.HSCROLL)
        redir=RedirectText(log)
        sys.stdout=redir
        print 'test'
        frame.Show()
        return True

class RedirectText:
    def __init__(self,aWxTextCtrl):
        self.out=aWxTextCtrl
    def write(self,string):
        self.out.WriteText(string)

app = XPinst()
app.MainLoop()

added:

class MyFrame(wx.Frame)
    def __init__(self, parent, id, title, size=(620,450), style=wx.STAY_ON_TOP|wx.DEFAULT_FRAME_STYLE):
        wx.Frame.__init__(self, parent, id, title, size=(620,450), style=wx.STAY_ON_TOP|wx.DEFAULT_FRAME_STYLE)

replaced:

frame = wx.Frame(None, -1, title='Redirect Test', size=(620,450), style=wx.STAY_ON_TOP|wx.DEFAULT_FRAME_STYLE)

with:

frame = MyFrame(None, -1, title='Redirect Test', size=(620,450), style=wx.STAY_ON_TOP|wx.DEFAULT_FRAME_STYLE)

Now, it doesn’t run…

I want to be able to call the MyFrame constructor more than once in my code passing different arguments

I tried many things…

instanciating MyFrame with all arguments
instanciating myFrame and with all, but default arguments
constructor method signature with all arguments
constructor method signature with all, but default arguments
calling parent constructor method with all arguments
calling parent constructor method with all, but default arguments

plus the tutorial http://zetcode.com/wxpython/ mentions a method where the number of default and optional arguments are different! (what’s the difference?)

UDPATE:

“it has seven parameters. The first parameter does not have a default value. The other six parameters do have. Those four parameters are optional. The first three are mandatory.” – http://zetcode.com/wxpython/firststeps/

UPDATE 2:

With semi-colon correction, i have just tried:

class MyFrame(wx.Frame):
    def __init__(self, parent, id, title, size, style):
        wx.Frame.__init__(self, parent, id, title, size, style)
  • I tell what arguments are going in (second line)
  • I call with the arguments that went in (third line)

UPDATE 3:

the full error message is:

Traceback (most recent call last):
  File "test.py", line 29, in <module>
    app = XPinst()
  File "test.py", line 8, in __init__
    wx.App.__init__(self, redirect, filename)
  File "/usr/lib/python2.6/dist-packages/wx-2.8-gtk2-unicode/wx/_core.py", line 7978, in __init__
    self._BootstrapApp()
  File "/usr/lib/python2.6/dist-packages/wx-2.8-gtk2-unicode/wx/_core.py", line 7552, in _BootstrapApp
    return _core_.PyApp__BootstrapApp(*args, **kwargs)
  File "test.py", line 10, in OnInit
    frame = MyFrame(None, -1, title='Redirect Test', size=(620,450), style=wx.STAY_ON_TOP|wx.DEFAULT_FRAME_STYLE)
  File "test.py", line 21, in __init__
    wx.Frame.__init__(self, parent, id, title, size, style)
  File "/usr/lib/python2.6/dist-packages/wx-2.8-gtk2-unicode/wx/_windows.py", line 497, in __init__
    _windows_.Frame_swiginit(self,_windows_.new_Frame(*args, **kwargs))
TypeError: Expected a 2-tuple of integers or a wxSize object.

Why didn’t it work?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T08:23:46+00:00Added an answer on May 16, 2026 at 8:23 am

    Runs fine for me with one tweak; you’re missing a colon after your subclassed wx.Frame statement.

    One comment; if you’re just "passing through" arguments to the parent initalizer, use *args and/or **kwargs to save some typing.

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

    If you want to modify or add particular arguments, you could just modify the dictionary kwargs, e.g.

    class MyFrame(wx.Frame):
        def __init__(self, *args, **kwargs):
            kwargs['size']=(1000,200)
            wx.Frame.__init__(self, *args, **kwargs)
    

    On running files for development:

    Run scripts you’re working on in the console, with python, not pythonw. The latter will just quit when it sees errors and send them off to lala-land.

    N:\Code>pythonw wxso.pyw
    
    N:\Code>rem nothing happened.
    
    N:\Code>python wxso.pyw
      File "wxso.pyw", line 24
        class MyFrame(wx.Frame)
                              ^
    SyntaxError: invalid syntax
    
    N:\Code>
    

    On keyword arguments:

    class MyFrame(wx.Frame):
        def __init__(self, parent, id, title, size, style):
            #wx.Frame.__init__(self, parent, id, title, size, style) # broken
            # equivalent to:
            #wx.Frame.__init__(self, parent, id=id, title=title, pos=size, size=style)
    
            # the below works.
            wx.Frame.__init__(self, parent, id, title=title, size=size, style=style)
    

    When you pass arguments as keywords e.g. title, size, style, their position to the function that actually takes them could be totally different. The first line there assigns "size" to whatever is the fifth argument in the wx.Frame.__init__ function, which is probably not size. It could be the 100th argument, but you use the keyword to tell it where to go.

    "Optional" is somewhat vague; keyword arguments supply defaults, but the default may be inappropriate.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In Groovy code something simple: #!/usr/bin/env groovy public class test { boolean val def
Okay, so i have this code i wrote: class Connection { public static StreamWriter
I have the following code which is executed from the command line: import cgi,time,os,json,sys,zipfile,urllib2
Okay full code now: DBOpenHelper: public class DBOpenHelper extends SQLiteOpenHelper { private SQLiteDatabase mDatabase;
Okay so I have two import pieces of code involved in this. This first
Okay so my code pretty much works... except if you click submit a second
Possible Duplicate: calling ASP function from javascript okay running this code : <script type=text/javascript>
Okay so i have this code: if (isset($_GET['book'])) { $query= SELECT book_id, title, authors.`author`
Okay I have updated my code quite a bit. I am getting a new
Okay I have updated my code a little, but I am still not exactly

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.