滚动窗口/面板制作Statictext全部在一行上

时间:2012-02-27 03:12:20

标签: wxpython

请帮忙!信息 -

程序:一个表示电子邮件的弹出框,在单击listctrl项目(“收件箱”)后生成。

情况:其中一封电子邮件的消息很长,部分消失了。需要一个垂直滚动条来阅读所有内容!但...

问题:一旦我将wx.Panel更改为wx.ScrolledWindow或ScrolledPanel(尝试两者=相同),消息的文本突然开始全部放在一行...我没有更长的需要一个垂直滚动条,我需要+有一个水平滚动条来读取它。

如果我改回wx.Panel,文本会再次自行封装(不会被告知)。它看起来整洁可爱......除了我仍然无法向下滚动阅读其余部分。如果我放回ScrolledWindow,突然所有的文字都是一行。我不明白。 :(为什么这样对我?

通过水平来回滚动来阅读邮件是如此不切实际,所以我真的需要像以前一样包装StaticText,使用垂直滚动条滚动浏览更长的电子邮件。我已经尝试输入main_message.Wrap(main_message.GetSize()。width)命令,但它什么也没做。

我希望它工作,以便在需要时有一个垂直滚动条...但不需要水平滚动条,即没有疯狂的文本突然决定它想要在一条线上。有人知道这是做什么的吗?

尽可能缩小代码管理范围:

class Message(wx.Frame):
    def __init__(self, parent, id, title):
        wx.Frame.__init__(self, parent, id, title, pos = (500, 100), size=(500, 500), style = wx.STAY_ON_TOP | wx.MAXIMIZE_BOX | wx.RESIZE_BORDER | wx.SYSTEM_MENU | wx.CAPTION)


        self.basicpanel = wx.ScrolledWindow(self, -1)
        self.basicpanel.SetScrollbars(1, 1, 1, 1)
        self.basicpanel.SetBackgroundColour("medium goldenrod")

        parent = self.GetParent()
        message = parent.email

        # email details e.g. sender, date, urgency, subject
        sender_st =  wx.StaticText(self.basicpanel, -1, "Sender:")
        status_st = wx.StaticText(self.basicpanel, -1, "Status:")
        date_st = wx.StaticText(self.basicpanel, -1, "Date:")
        priority_st = wx.StaticText(self.basicpanel, -1, "Priority:")
        subject_st = wx.StaticText(self.basicpanel, -1, "Subject:")

        answer_sender = wx.StaticText(self.basicpanel, -1, message.sender)
        answer_status = wx.StaticText(self.basicpanel, -1, message.status)
        answer_date = wx.StaticText(self.basicpanel, -1, message.date)
        answer_priority = wx.StaticText(self.basicpanel, -1, message.priority)
        answer_subject = wx.StaticText(self.basicpanel, -1, message.subject)

        # main body of email
        main_message = wx.StaticText(self.basicpanel, -1, message.txt)

        # create a box sizer to put in the email details like sender, date, et
        self.messagebox = wx.StaticBox(self.basicpanel, -1, '', (5,5))
        self.fgs_message = wx.FlexGridSizer(3, 4, 5, 15)
        self.fgs_message.AddMany([(sender_st, 1, wx.EXPAND), (answer_sender, 1, wx.EXPAND), (status_st, 1, wx.EXPAND), (answer_status, 1, wx.EXPAND), (date_st, 1, wx.EXPAND), (answer_date, 1, wx.EXPAND), (priority_st, 1, wx.EXPAND), (answer_priority, 1, wx.EXPAND), (subject_st, 1, wx.EXPAND), (answer_subject, 1, wx.EXPAND)])
        self.boxmessagesizer = wx.StaticBoxSizer(self.messagebox, wx.VERTICAL)
        self.boxmessagesizer.Add(self.fgs_message, 1, wx.ALL, 5)

        # create a sizer to include the above details and the main message or body of email
        self.messagebasicsizer = wx.BoxSizer(wx.VERTICAL)
        self.messagebasicsizer.Add(self.boxmessagesizer, 0, wx.EXPAND | wx.ALL, 10)
        self.messagebasicsizer.Add(main_message, 1, wx.EXPAND | wx.ALL, 10)

        # create buttons at the bottom and a horizontal sizer to put them on same line
        self.buttonreply = wx.Button(self.basicpanel, 1, 'Reply', (20,10))
        self.buttondelete = wx.Button(self.basicpanel, 1, 'Close + Delete', (40, 10))
        self.buttonsave = wx.Button(self.basicpanel, 1, 'Close + Save', (40,10))
        self.horisizer = wx.BoxSizer(wx.HORIZONTAL)
        self.horisizer.AddMany([(self.buttonreply, 0, wx.EXPAND | wx.ALL, 10), (self.buttondelete, 0, wx.EXPAND | wx.ALL, 10), (self.buttonsave, 0, wx.EXPAND | wx.ALL, 10)])

        # add buttons to sizer with message details and message
        self.messagebasicsizer.Add(self.horisizer, 0, wx.EXPAND | wx.ALIGN_CENTRE | wx.ALL, 10)


        self.basicpanel.SetSizer(self.messagebasicsizer)
        self.Bind(wx.EVT_BUTTON, self.OnDestroy)

        self.Show(True)

1 个答案:

答案 0 :(得分:1)

您应该使用wordwrap模块:http://www.wxpython.org/docs/api/wx.lib.wordwrap-module.html。我在这里有一个例子:http://www.blog.pythonlibrary.org/2008/06/11/wxpython-creating-an-about-box/

或者将文本放入只读的多行TextCtrl中。然后你将自动滚动。后者可能更容易,并且在美学上看起来更好。