python面向对象的一个问题

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python面向对象的一个问题相关的知识,希望对你有一定的参考价值。

不知道是什么原因,求大神!!!!!!!!!!!!
# -*- coding: cp936 -*-import wxclass MyFrame(wx.Frame): def __init__(self,parent,id): wx.Frame.__init__(self,parent,id,'简易文本编辑器 版本号0.01', size=(415,400)) panel = wx.Panel(self) #打开文件 loadButton = wx.Button(panel,label='打开',pos=(225,5),size=(80,25)) self.Bind(wx.EVT_BUTTON,self.load,loadButton)
#保存文件 saveButton = wx.Button(panel,label='保存',pos=(315,5),size=(80,25)) self.Bind(wx.EVT_BUTTON,self.save,saveButton)
#获取帮助 helpButton = wx.Button(panel,label='帮助',pos=(225,35),size=(80,25)) self.Bind(wx.EVT_BUTTON,self.helpdoc,helpButton)
#退出程序 exitButton = wx.Button(panel,label='退出',pos=(315,35),size=(80,25)) self.Bind(wx.EVT_BUTTON,self.exitPro,exitButton)
filename = wx.TextCtrl(panel,pos=(5,5),size=(210,25)) contents = wx.TextCtrl(panel,pos=(5,65),size=(390,290), style=wx.TE_MULTILINE|wx.HSCROLL)
welcome = wx.StaticText(panel,-1,"欢迎使用!",pos=(5,35),size=(210,25),style=wx.ALIGN_CENTER) welcome.SetForegroundColour('blue') welcome.SetBackgroundColour('green')
def load(self,event): file = open(filename.GetValue()) contents.SetValue(file.read()) file.close()
def save(self,event): file = open(filename.GetValue(),'w') file.write(contents.GetValue()) file.close()
def helpdoc(self,event): dlg = wx.MessageDialog(None,u'这是一个简易的文本编辑器,可以实现文本的编辑', u'帮助') dlg.ShowModal() dlg.Destroy() def exitPro(self,event): self.Close() if __name__ == '__main__': app = wx.App() frame = MyFrame(parent=None,id=-1) frame.Show() app.MainLoop()

filename 改成self.filename 参考技术A 报什么错啊,也没写出来??

以上是关于python面向对象的一个问题的主要内容,如果未能解决你的问题,请参考以下文章

Python:面向对象基础

python--面向对象

Python第七章-面向对象

python之路 面向对象

python----面向对象

python 面向对象调用问题