Python/WXWidgets:ST_NO_AUTORESIZE不受表彰wx.StaticTex

2024-06-07 10:53:30 发布

您现在位置:Python中文网/ 问答频道 /正文

我想在屏幕中央以固定大小显示一个视图,其中一些静态文本在水平和垂直居中显示。在

到目前为止,我有以下代码:

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.对话框或者wx.框架. 在

如您所见,我确实定义了NO_AUTORESIZE标志,但这并没有受到尊重。在

有人能解释一下发生了什么吗?在

Python 2.7.5/wxWidgets 2.8.12.1/Mac OS X 10.8.4


Tags: notext文本selfsizeinitstyle静态
1条回答
网友
1楼 · 发布于 2024-06-07 10:53:30

这是MacOSX的本机对话实现的一个限制。在

以下是它在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()

相关问题 更多 >

    热门问题