如何使用wx.python演示代码

时间:2015-03-14 13:21:02

标签: python wxpython demo

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

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

如果有人能帮我解决这个问题,我真的很感激。

由于演示使用演示框架:

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

但我可能做错了,因为我不工作。

非常感谢任何帮助。

2 个答案:

答案 0 :(得分:0)

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

答案 1 :(得分:0)

我在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()