Python/WXWidgets:ST_NO_AUTORESIZE不适用于wx.StaticText
我想在屏幕中央弹出一个固定大小的视图,其中一些静态文本在水平和垂直方向居中显示 到目前为止,我有以下代码:Python/WXWidgets:ST_NO_AUTORESIZE不适用于wx.StaticText,python,wxwidgets,Python,Wxwidgets,我想在屏幕中央弹出一个固定大小的视图,其中一些静态文本在水平和垂直方向居中显示 到目前为止,我有以下代码: import wx class DisplayText(wx.Dialog): def __init__(self, parent, text="", displayMode=0): # Initialize dialog wx.Dialog.__init__(self, parent, size=(480,320), style=( wx.DI
import wx
class DisplayText(wx.Dialog):
def __init__(self, parent, text="", displayMode=0):
# Initialize dialog
wx.Dialog.__init__(self, parent, size=(480,320), style=( wx.DIALOG_EX_METAL | wx.STAY_ON_TOP ) )
# Center form
self.Center()
self.txtField = wx.StaticText(self, label=text, pos=(80,120), size=(320,200), style=wx.ALIGN_CENTRE_HORIZONTAL | wx.ST_NO_AUTORESIZE)
self.txtField.SetFont(wx.Font(24, wx.DEFAULT, wx.BOLD, 0))
app = wx.App(False)
c = DisplayText(None, text="Now is the time for all good men to come to the aid of their country.")
c.Show()
app.MainLoop()
我们的目标是让文本垂直居中,但现在,我只是想明确静态文本在框架上的位置
在短暂的一瞬间,文本显示在我放置它的位置,但随后它迅速跳到窗口的最上边并扩展到最大宽度。(我故意将宽度和位置设置得较低,以便能够查看是否发生了这种行为。)
无论我使用wx.Dialog还是wx.Frame
正如您所看到的,我确实定义了NO_AUTORESIZE标志,但这并没有得到尊重
有人能解释发生了什么事吗
Python 2.7.5/wxWidgets 2.8.12.1/Mac OS X 10.8.4证明这是Mac OS X本机对话框实现的一个限制 下面的内容使它在OSX上工作。我从未在Windows上尝试过,但从其他论坛的帖子来看,它似乎在Windows上也能正常工作
import wx
class DisplayText(wx.Dialog):
def __init__(self, parent, text="", displayMode=0):
# Initialize dialog
wx.Dialog.__init__(self, parent, size=(480,320), style=( wx.DIALOG_EX_METAL | wx.STAY_ON_TOP ) )
# Center form
self.Center()
# (For Mac) Setup a panel
self.panel = wx.Panel(self)
# Create text field
self.txtField = wx.StaticText(self.panel, label=text, pos=(80,120), size=(320,200), style=wx.ALIGN_CENTRE_HORIZONTAL | wx.ST_NO_AUTORESIZE)
self.txtField.SetFont(wx.Font(24, wx.DEFAULT, wx.BOLD, 0))
self.txtField.SetAutoLayout(False)
app = wx.App(False)
c = DisplayText(None, text="Now is the time for all good men to come to the aid of their country.")
c.Show()
app.MainLoop()