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

  • Home
  • SEARCH
  • 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 8251133
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T00:08:21+00:00 2026-06-08T00:08:21+00:00

I have a button that either creates a new child frame or shows the

  • 0

I have a button that either creates a new child frame or shows the one that was already created. I ran into a problem when I tried to use Show() alone — if the user had exited the child frame, I would get an error because I was accessing a frame that no longer existed. I am currently using try/except to get around this, but is there a better way? Perhaps a Raise()-like function that handles this, or a way to check if the frame exists?

code:

#!/usr/bin/env python

import wx

class LogWindow(wx.Frame):
    def __init__(self, parent):
        wx.Frame.__init__(self, parent)
        self.logger = wx.TextCtrl(self, style=wx.TE_MULTILINE | wx.TE_READONLY)

    def Print(self):
        self.Raise()
        self.logger.AppendText("Hello, world\n")

class MainWindow(wx.Frame):
    def __init__(self, parent, id, title):
        wx.Frame.__init__(self, parent, id, title)
        panel=wx.Panel(self)

        label = wx.StaticText(panel, -1, "Log this message:", pos=(10,10))
        goButton = wx.Button(panel, label="Log", pos=(10,50))
        self.Bind(wx.EVT_BUTTON, self.OnClick, goButton)
        self.logWin = LogWindow(self)

    #++++++++++++++++++++++++++
    def OnClick(self, event):
        try:
            self.logWin.Show()
        except:
            self.logWin = LogWindow(self)
            self.logWin.Show()

        self.logWin.Print()
    #++++++++++++++++++++++++++

class MyApp(wx.App):
    def OnInit(self):
        frame = MainWindow(None, -1, "MyApp")
        frame.Show(True)
        self.SetTopWindow(frame)
        return True

#************************************************

if __name__ == "__main__":
    app = MyApp(0)
    app.MainLoop()

The error I receive with self.logWin.Show() without the try/except is

wx._core.PyDeadObjectError: The C++ part of the LogWindow object has been deleted, attribute access no longer allowed.

  • 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-06-08T00:08:22+00:00Added an answer on June 8, 2026 at 12:08 am

    You could use isinstance to check if it’s still there. See this thread for more info: https://groups.google.com/forum/?fromgroups#!topic/wxpython-users/lMAylDnC7vM

    Or you could just try:

    if self.logWin:
        self.logWin.Show()
    

    http://wxpython-users.1045709.n5.nabble.com/is-there-a-method-to-test-if-an-wx-object-exists-td2356531.html

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

Sidebar

Related Questions

I have event Button that creates text box in run time. Private Sub Button1_Click(ByVal
I have a button that, when pressed, will add a new HTML row. Within
I have a button that i basically want to either show or hide it
My solution for one problem has created a new problem for me. In my
I have button that a user selects and I pop up a AlertDialog to
I have a button that can have a focus css class associated with it
I have a button that cause an image to display the image full screen
I have a button that I want to make disappear if anything is tapped
I have a button that is supposed to close a modal panel and render
I have a button that when clicked will run a stored procedure on a

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.