WxPython: Cross-Platform Way to Conform Ok/Cancel Button Order

自古美人都是妖i 提交于 2019-12-06 13:15:19

The appearance of a dialog can change only if you use stock dialogs (like wx.FileDialog), if you make your own the layout will stay the same on every platform.

wx.Dialog has a CreateStdDialogButtonSizer method that creates a wx.StdDialogButtonSizer with standard buttons where you might see differences in layout on different platforms but you don't have to use that.

You can use a StdDialogButtonSizer

http://www.wxpython.org/docs/api/wx.StdDialogButtonSizer-class.html

So long as your buttons have the standard IDs they will be put in the correct order.

Just to add a wrinkle though, on a Mac for instance, a preferences dialog would not have OK / Cancel buttons. It would automatically apply the preferences as they were entered (or at least on dialog close). So you'd still have to do some platform sniffing in that case.

If you're going to use wx (or any other x-platform toolkit) you'd better trust that it does the right thing, mon!-)

There's the GenericMessageDialog widget that should do the right thing depending on the platform (but I've never used it so I'm not sure it does). See the wxPython demo.

You can also use the SizedControls addon library (it's part of wxPython). The SizedDialog class helps to create dialogs that conform to the Human Interface Guidelines of each platform. See the wxPython demo.

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