首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > perl python >

wxpython 代码的疑义

2012-10-11 
wxpython 代码的疑问Python code# Chapter 1: Getting Started# Recipe 7: Stock IDs#import osimport wx

wxpython 代码的疑问

Python code
# Chapter 1: Getting Started# Recipe 7: Stock ID's#import osimport wxclass MyApp(wx.App):    def OnInit(self):        self.frame = MyFrame(None, title="Stock Id's")        self.SetTopWindow(self.frame)        self.frame.Show()        return Trueclass MyFrame(wx.Frame):    def __init__(self, parent, id=wx.ID_ANY, title="",                  pos=wx.DefaultPosition, size=wx.DefaultSize,                 style=wx.DEFAULT_FRAME_STYLE,                 name="MyFrame"):        super(MyFrame, self).__init__(parent, id, title,                                       pos, size, style, name)        # Attributes        self.panel = wx.Panel(self)        # Setup        ok_btn = wx.Button(self.panel, wx.ID_OK)        cancel_btn = wx.Button(self.panel, wx.ID_CANCEL,                               pos=(100, 0))        menu_bar = wx.MenuBar()        edit_menu = wx.Menu()        edit_menu.Append(wx.NewId(), "Test")        edit_menu.Append(wx.ID_PREFERENCES)        menu_bar.Append(edit_menu, "Edit")        self.SetMenuBar(menu_bar)if __name__ == "__main__":    app = MyApp(False)    app.MainLoop()


主要是不明白
Python code
ok_btn = wx.Button(self.panel, wx.ID_OK)cancel_btn = wx.Button(self.panel, wx.ID_CANCEL,                       pos=(100, 0))

两句中创建ok_btn , cancel_btn这两个引用的作用?
本来我认为只需有
wx.Button(self.panel, wx.ID_OK)
wx.Button(self.panel, wx.ID_CANCEL,pos=(100, 0))

这两句就OK的啦,怎么还要多此一举创建ok_btn , cancel_btn这两个引用呢?

还有 menu_bar.Append(edit_menu, "Edit")
Edit的前面加不加&有何区别?


[解决办法]
探讨
两句中创建ok_btn , cancel_btn这两个引用的作用?
本来我认为只需有
wx.Button(self.panel, wx.ID_OK)
wx.Button(self.panel, wx.ID_CANCEL,pos=(100, 0))

热点排行