OK/CANCEL order in “custom” dialogs created with wxglade

核能气质少年 提交于 2020-01-05 08:09:25

问题


I've noticed that standard dialogs some CANCEL and OK buttons in different order under Windows and under Linux. Under Linux, you get "[CANCEL] [OK]", and under Windows, "[OK] [CANCEL]".

I have no problem with the standard dialogs, but then my "custom dialogs" must be tweaked to match the same order, dependent of the O.S.

My doubts:

1.- It seems to exist a class called wx.StdDialogButtonSizer, but I'm not sure how it should be used. Can somebody post any working simple / working example?

And the "Main question":

2.- I use wxglade to "build" code for the dialogs, so I'm not sure I can use StdDialogButtonSizer. Is there a way to define the dialog with a given order, and in run-time check if the buttons follow the right order and "exchange" those two widgets if not?

Thanks


回答1:


The StdDialogButtonSizer is definitely the way to go for custom dialogs. Here's a simple example:

import wx

########################################################################
class SampleDialog(wx.Dialog):
    """"""

    #----------------------------------------------------------------------
    def __init__(self, parent):
        """Constructor"""
        wx.Dialog.__init__(self, parent, title="Tutorial")

        btnOk = wx.Button(self, wx.ID_OK)
        btnCancel = wx.Button(self, wx.ID_CANCEL)

        btnSizer = wx.StdDialogButtonSizer()
        btnSizer.AddButton(btnOk)
        btnSizer.AddButton(btnCancel)
        btnSizer.Realize()
        self.SetSizer(btnSizer)

#----------------------------------------------------------------------
if __name__ == '__main__':
    app = wx.App(False)
    dlg = SampleDialog(None)
    dlg.ShowModal()

See also WxPython: Cross-Platform Way to Conform Ok/Cancel Button Order or http://wxpython-users.1045709.n5.nabble.com/wx-StdDialogButtonSizer-and-wx-ID-SAVE-td2360032.html

I don't know if there's a way to do this in Glade or not though.



来源:https://stackoverflow.com/questions/6693660/ok-cancel-order-in-custom-dialogs-created-with-wxglade

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!