Hi all,

I have a frame and on click of a button, a dialog box is popped up. I want the dialog box to pop up always at the centre of the frame irrespective of where the frame is located on the screen. Presently this is not happeneing.

Help needed!

Regards,
Dinil

Well there might be a better way but you could go something like:

# lets assubme variable self.frame is your frame
class Frame(wx.Frame)
    def __init__(self)
        wx.Frame.__init__(self,None,pos = (100,100))
        self.Show()
        self.Dialog()
    def Dialog()
        d = wx.Dialo("arguments here")
        d.Position = (self.frame.Position[0]+(self.frame.Size[0]/2,self.frame.Position[1]+(self.frame.Size[1]/2
        d.ShowModal()

I think that should work.
It takes the frames position and adds half of its size to get the position of the dialog.

Hi,
There are some sytax errors in your code i guess. Is it working on your system?

yeah sorry its rather stuffed up code. Ill try and fix that, the main thing i want to grab from that is the idea that to position it in the middle all you have to do is get the parents position and add half of its size.

That is just the basic concept im trying to show. Sorry it didnt work.

Hi,
I tried this code. But still its not working.
I am using messageDialog. The code is given below:

dlg = wx.MessageDialog(None,"You dont have sufficient priviliges!", '787 RPC:Error',
wx.OK|wx.ICON_EXCLAMATION)
dlg.CenterOnParent()
res = dlg.ShowModal()
dlg.Destroy()

This dialog box does not pop up at the centre of the parent frame instead it occupies alwyas the centre of the screen irrespective of the position of the frame. How do I set the frame as the parent of this dialogbox?

Regards,
Dinil

If CenterOnParent is centering on the screen that means your dialog isn't being called with the proper parent. You probably have None set for this value when calling the dialog. Double-check your code to make sure you're providing the object with the proper arguments on initialization.

HTH

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.