如何使用 wx.python 演示代码

How to use wx.python demos code

我是 wx.python 和 python 的新手,想在我自己的应用程序中使用 MultiSplitterWindow.py 演示代码。

我已经阅读了有关此主题的其他 Whosebug 条目,但那里给出的答案似乎对我不起作用。

如果有人能帮我解决这个问题,我将不胜感激。

由于演示使用了演示框架:

if __name__ == '__main__':
    import sys,os
    import run
    run.main(['', os.path.basename(sys.argv[0])] + sys.argv[1:])

它在我的应用程序中不起作用,我尝试使用中给出的示例替换上面的内容:

[] http://wiki.wxpython.org/Using%20wxPython%20Demo%20Code

但我可能做错了什么,因为我没有工作。

非常感谢任何帮助。

从这里下载演示 http://wxpython.org/download.php 安装并转到 C:\Program Files\wxPython3.0-Docs-and-Demos\demo 和 运行.

我在 wxPython wiki 上写过:

大多数时候,您可以复制有问题的小部件代码的相关部分并将其粘贴到您自己的代码中。您不想要的部分是对 self.log 的引用。这只允许演示记录消息并且是特定于演示的代码。不过,我实际上会重写我的初始示例,使其看起来如下所示:

import wx

########################################################################
class MyPanel(wx.Panel):
    """"""

    #----------------------------------------------------------------------
    def __init__(self, parent):
        """Constructor"""
        wx.Panel.__init__(self, parent)


########################################################################
class MyFrame(wx.Frame):

    #----------------------------------------------------------------------
    def __init__(self):
        wx.Frame.__init__(self, None, title="Demo Test")
        panel = MyPanel(self)

        self.Show()

#----------------------------------------------------------------------
if __name__ == '__main__':
    app = wx.App(False)
    frame = MyFrame()
    app.MainLoop()

现在,如果您想从演示中复制代码,则不必将所有 self 实例更改为“self.panel”:

import wx
from wx.lib.wordwrap import wordwrap

########################################################################
class MyPanel(wx.Panel):
    """"""

    #----------------------------------------------------------------------
    def __init__(self, parent):
        """Constructor"""
        wx.Panel.__init__(self, parent)

        b = wx.Button(self, -1, "Show a wx.AboutBox", (50,50))
        self.Bind(wx.EVT_BUTTON, self.OnButton, b)

    def OnButton(self, evt):
        # First we create and fill the info object
        info = wx.AboutDialogInfo()
        info.Name = "Hello World"
        info.Version = "1.2.3"
        info.Copyright = "(C) 2006 Programmers and Coders Everywhere"
        info.Description = wordwrap(
            "A \"hello world\" program is a software program that prints out "
            "\"Hello world!\" on a display device. It is used in many introductory "
            "tutorials for teaching a programming language."

            "\n\nSuch a program is typically one of the simplest programs possible "
            "in a computer language. A \"hello world\" program can be a useful "
            "sanity test to make sure that a language's compiler, development "
            "environment, and run-time environment are correctly installed.",
            350, wx.ClientDC(self))
        info.WebSite = ("http://en.wikipedia.org/wiki/Hello_world", "Hello World home page")
        info.Developers = [ "Joe Programmer",
                            "Jane Coder",
                            "Vippy the Mascot" ]

        info.License = wordwrap(licenseText, 500, wx.ClientDC(self))

        # Then we call wx.AboutBox giving it that info object
        wx.AboutBox(info)


########################################################################
class MyFrame(wx.Frame):

    #----------------------------------------------------------------------
    def __init__(self):
        wx.Frame.__init__(self, None, title="Demo Test")
        panel = MyPanel(self)

        self.Show()

licenseText = "blah " * 250 + "\n\n" +"yadda " * 100

#----------------------------------------------------------------------
if __name__ == '__main__':
    app = wx.App(False)
    frame = MyFrame()
    app.MainLoop()