博客
关于我
wxpython的Hello,World代码探索
阅读量:380 次
发布时间:2019-03-05

本文共 3492 字,大约阅读时间需要 11 分钟。

python界面编程资料

#!/bin/python"""Hello World, but with more meat."""import wxclass HelloFrame(wx.Frame):    """    A Frame that says Hello World    """    def __init__(self, *args, **kw):        # ensure the parent's __init__ is called        super(HelloFrame, self).__init__(*args, **kw)        # create a panel in the frame        pnl = wx.Panel(self)        # and put some text with a larger bold font on it        st = wx.StaticText(pnl, label="Hello Friend!", pos=(500,260))        font = st.GetFont()        font.PointSize += 50        font = font.Bold()        st.SetFont(font)        # create a menu bar        self.makeMenuBar()        # and a status bar        self.CreateStatusBar()        self.SetStatusText("Welcome to wxPython100!")    def makeMenuBar(self):        """        A menu bar is composed of menus, which are composed of menu items.        This method builds a set of menus and binds handlers to be called        when the menu item is selected.        """                # Make a file menu with Hello and Exit items        fileMenu = wx.Menu()        # The "\t..." syntax defines an accelerator key that also triggers        # the same event        helloItem = fileMenu.Append(-1, "&Hello...\tCtrl-H",                 "Help string shown in status bar for this menu item")        fileMenu.AppendSeparator()        # When using a stock ID we don't need to specify the menu item's        # label        exitItem = fileMenu.Append(wx.ID_EXIT)        # Now a help menu for the about item        helpMenu = wx.Menu()        aboutItem = helpMenu.Append(wx.ID_ABOUT)        # Make the menu bar and add the two menus to it. The '&' defines        # that the next letter is the "mnemonic" for the menu item. On the        # platforms that support it those letters are underlined and can be        # triggered from the keyboard.        menuBar = wx.MenuBar()        menuBar.Append(fileMenu, "&File")        menuBar.Append(helpMenu, "&Help")        # Give the menu bar to the frame        self.SetMenuBar(menuBar)        # Finally, associate a handler function with the EVT_MENU event for        # each of the menu items. That means that when that menu item is        # activated then the associated handler function will be called.        self.Bind(wx.EVT_MENU, self.OnHello, helloItem)        self.Bind(wx.EVT_MENU, self.OnExit,  exitItem)        self.Bind(wx.EVT_MENU, self.OnAbout, aboutItem)    def OnExit(self, event):        """Close the frame, terminating the application."""        self.Close(True)    def OnHello(self, event):        """Say hello to the user."""        wx.MessageBox("This is a wxPython Hello World sample",                       "Hello again from wxPython")                          def OnAbout(self, event):        """Display an About Dialog"""        wx.MessageBox("This is a wxPython Hello World sample",                       "About Hello World 2",                      wx.OK|wx.ICON_INFORMATION)if __name__ == '__main__':    # When this module is run (not imported) then create the app, the    # frame, show it, and start the event loop.    app = wx.App()    frm = HelloFrame(None, title='Hello World 100')    frm.Show()    app.MainLoop()

super()的解释

 

fileMenu.AppendSeparator()

这个函数是在两个子选项之间添加分隔符

 

MessageBox的标题是逗号后面的那句,消息内容是第一句。

 

wx.OK|wx.ICON_INFORMATION

红色矩形框,这一句少了会报错

 

不加到最后一个OnAbout也不行

 

每句都加也不行

只能加到最后一句

 

helloItem = fileMenu.Append(-1, "&Hello...\tCtrl-H",

"Help string shown in status bar for this menu item")

-1可以,-2可以,-3可以,-4不行,-4以下都不行。0---10000可以

转载地址:http://klywz.baihongyu.com/

你可能感兴趣的文章
mysql cmake 报错,MySQL云服务器应用及cmake报错解决办法
查看>>
Multiple websites on single instance of IIS
查看>>
mysql CONCAT()函数拼接有NULL
查看>>
multiprocessing.Manager 嵌套共享对象不适用于队列
查看>>
multiprocessing.pool.map 和带有两个参数的函数
查看>>
MYSQL CONCAT函数
查看>>
multiprocessing.Pool:map_async 和 imap 有什么区别?
查看>>
MySQL Connector/Net 句柄泄露
查看>>
multiprocessor(中)
查看>>
mysql CPU使用率过高的一次处理经历
查看>>
Multisim中555定时器使用技巧
查看>>
MySQL CRUD 数据表基础操作实战
查看>>
multisim变压器反馈式_穿过隔离栅供电:认识隔离式直流/ 直流偏置电源
查看>>
mysql csv import meets charset
查看>>
multivariate_normal TypeError: ufunc ‘add‘ output (typecode ‘O‘) could not be coerced to provided……
查看>>
MySQL DBA 数据库优化策略
查看>>
multi_index_container
查看>>
MySQL DBA 进阶知识详解
查看>>
Mura CMS processAsyncObject SQL注入漏洞复现(CVE-2024-32640)
查看>>
Mysql DBA 高级运维学习之路-DQL语句之select知识讲解
查看>>