0

I make some experiences in Python especially in wxpython from EventGhost but I have some generally problem with classes. I have watched around and tried a lot but have no success.

My problem is that I want to close my Gui from a button inside my "MyDialog()" class:

class ShowInputDialog(eg.ActionBase):
    name = "Show Input Dialog"  
    description = "Show an input dialog that allows you to create an EventGhost event that you can then use to trigger AutoRemote messages or notifications"
    def __call__(self):
        class MyDialog():
            def __init__(self):

                ########################Main Dialog###########################
                no_sys_menu = wx.CLIP_CHILDREN | wx.STAY_ON_TOP | wx.FRAME_NO_TASKBAR | wx.NO_BORDER | wx.FRAME_SHAPED
                self.Dialog = wx.Frame(None, wx.ID_ANY, "Hello World", style=no_sys_menu, size=(400,600))

                ########################Header###########################
                Header = wx.Panel(self.Dialog, wx.ID_ANY, size=(400,600)) 
                HeaderSizer = wx.GridSizer(rows=1, cols=2, hgap=5, vgap=5)

                HeaderSizer.Add(wx.StaticText(Header, label="Hello World"), flag=wx.ALIGN_CENTER_VERTICAL)

                button = wx.Button(Header, label='close')
                button.Bind(wx.EVT_BUTTON, self.close)
                HeaderSizer.Add(button, 0, wx.ALIGN_RIGHT, 0)

                Header.SetSizer(HeaderSizer) 

                upDownSizer = wx.BoxSizer(wx.VERTICAL)
                upDownSizer.Add(Header, 0, flag=wx.EXPAND)            
                self.Dialog.SetSizer(upDownSizer) 

                self.Dialog.Fit()
                self.Dialog.Show()


            def close(self, event):
                self.Close()
                print "see you soon"

        wx.CallAfter(MyDialog)  

if I call "close" from my button I get

AttributeError: MyDialog instance has no attribute 'Close'

but how to call "Close"? I Have read about to super the init of "MyDialog" but have no success doing that and also don't know if this would clear my problem.

Thanks and be not so hard to a noob

1 Answer 1

1

self is your own class, it is not a wx Class ... if you want it to have the attributes of a wx.Dialog you need to inherit from wx.Dialog

the easiest solution is probably to just call close on self.Dialog which appears to be your actual instance of a dialog

def close(self, event):
     self.Dialog.Close()
     print "see you soon"
Sign up to request clarification or add additional context in comments.

3 Comments

I habe tried that before but getting something like AttributeError: MyDialog methode has no instance 'Dialog'
no thats not the error you got ... if you want help you will need to put the actual error message you get ...
Sorry for that I wasn't home. AND Sorry you got right. I tested like you dit it (I thought I have try it before) and now It's working than thought. thanks

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.