如何在wxpython中的现有消息框中添加一些文本?

时间:2015-07-22 20:01:30

标签: python-2.7 wxpython messagebox

我是wxpython的新手。我想使用wxpython GUI编程将一些文本添加到现有消息框中。我在网上搜索,但我无法获得任何有用的信息。你能帮我解决这个问题吗?

我的目标是运行代码,然后在代码运行到窗口期间打印一些文本。

谢谢,

我希望有这样的东西:

    outPut = 'Simulation is done' 
    wx.MessageBox(outPut, "Results")
    newText = 'The results are:\n' #add this text to previous MessageBox

2 个答案:

答案 0 :(得分:1)

我不认为你可以用MessageBox来做,但是使用ProgressDialog怎么样?我更新了代码并对其进行了测试:

# -*- coding: utf-8 -*-
#!/usr/bin/env python

import wx
print(wx.VERSION_STRING)

import wx.lib.sized_controls as sc


class abc(sc.SizedFrame):

    def __init__(self, parent, id):
        super(abc, self).__init__(parent, id, 'Frame aka window')
        cpane = self.GetContentsPane()

        button1 = wx.Button(cpane, label="ProgressDialog 1 sample")
        button1.Bind(wx.EVT_BUTTON, self.pdlg1)

        button1 = wx.Button(cpane, label="ProgressDialog 2 sample")
        button1.Bind(wx.EVT_BUTTON, self.pdlg2)


    def pdlg1(self, evt):
        dlgPro = wx.ProgressDialog(u"Simulation progress 1",
                                   u"It is starting",
                                   3,
                                   None,
                                   wx.PD_AUTO_HIDE | wx.PD_APP_MODAL)
        # do something
        dlgPro.Update(1, u"first one is done")
        # do something
        wx.Yield()
        wx.Sleep(1)
        dlgPro.Update(2, u"second one is done")
        # do something
        wx.Yield()
        wx.Sleep(1)
        dlgPro.Update(3, u"we are finished")

    def pdlg2(self, evt):
        dlgPro = wx.ProgressDialog(u"Simulation progress 2",
                                   u"It is starting",
                                   -1,
                                   None,
                                   wx.PD_AUTO_HIDE | wx.PD_APP_MODAL)
        # do something
        dlgPro.Pulse(u"first one is done")
        # do something
        wx.Yield()
        wx.Sleep(1)
        dlgPro.Pulse(u"second one is done")
        # do something
        wx.Yield()
        wx.Sleep(1)
        dlgPro.Pulse(u"we are finished")

if __name__ == '__main__':
    app = wx.App()
    frame = abc(None, -1)
    frame.Show()
    app.MainLoop()

http://wxpython.org/Phoenix/docs/html/ProgressDialog.html?highlight=progress

答案 1 :(得分:0)

要将文本添加到文本框,您必须向框架添加某种文本对象。例如

class MyFrame(wx.Frame):
  def __init__(self, *args, **kwargs):
      wx.Frame.__init__(*args, **kwargs)
      self.text = wx.StaticText(self, wx.ID_ANY, "Hello World!")

创建一个框架,其中包含文本“Hello,World”。它是静态文本,意味着用户无法更改它。如果您想要可以更改的文字,请查看wx.TextCtrl