1
推導出其他一些主題指出了一個通用的MessageBox,wx.MessageDialog
並不很多API函數,如Destroy()
等的外部調用因此,有必要建立源自一個wx.GenericMessageBox
迴應wx.Dialog
。 這就是:從的wx.Dialog
import wx
class GenericMessageBox(wx.Dialog):
def __init__(self, parent, text, title = ''):
wx.Dialog.__init__(self, parent, -1, title = title, size = (360,120), style = wx.DEFAULT_DIALOG_STYLE)
panel = wx.Panel(self, wx.ID_ANY, size = (360, 50), pos = (0,0))
panel.SetBackgroundColour('#FFFFFF')
label = wx.StaticText(panel, -1, text, pos = (50,20))
panel2 = wx.Panel(self, wx.ID_ANY, size = (360, 40), pos = (0, 50))
btn = wx.Button(panel2, wx.ID_OK, pos = (250,7))
self.ShowModal()
app = wx.App()
frame = wx.Frame(None, 0, 'Test')
frame.Show()
GenericMessageBox(frame, 'This is a message box that is derived from wx.Dialog. You can Destroy() it from anywhere in the code.', 'Test')
app.MainLoop()
不像wx.lib.agw.genericmessagedialog
,這個人的目標是到最接近期待能夠原生操作系統的外觀(這裏的Windows外觀)。 [genericmessagedialog
具有的按鈕,這是不是像Windows'本地外觀圖片]
它是如何將有可能提高,從而該對話框中,如果需要StaticText
兩行的大小會自動增加?
此外,確定按鈕(x,y)定位是否正常並居中在我機器的灰色面板上,但在其他平臺上是否一樣?
(我覺得這樣的一個片段可能是社區有用。)
非常感謝。是否可以爲'wx.StaticText'設置最大寬度,以便自動分割成幾行文本的段落太長? – Basj
@Basj是的,嘗試** self.m_staticText.Wrap(SIZE)** –