新手问题请教 TypeError: script() takes exactly 1 argument (2 give)

xingyun1113 2014-10-10 11:45:16
# -*- coding: utf-8 -*-


import wx
import wx.xrc
import _winreg
from wx import App, CAPTION
from wxPython._wx import NULL



class Script ( wx.Frame ):

def __init__( self, parent ):
wx.Frame.__init__ ( self, parent, id = wx.ID_ANY, title = u"Script Tool", pos = wx.DefaultPosition, size = wx.Size( 320,600 ), style = wx.DEFAULT_FRAME_STYLE|wx.TAB_TRAVERSAL )

.
.
.


self.Bind(wx.EVT_MENU, self.OnAbout, self.m_menuItem4)
self.Bind(wx.EVT_BUTTON, self.script, self.m_button4)

self.Centre( wx.BOTH )


def script(self):
b = self.get_desktop()
print b
#m_sctipt = open((self.get_desktop()+'\\'+self.m_textCtrl1.GetValue()+'.txt'),'w')
#m_sctipt.close()

def get_desktop(self):
key = _winreg.OpenKey(_winreg.HKEY_CURRENT_USER,r'Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders',)
return _winreg.QueryValueEx(key, "Desktop")[0]'''




app = wx.App()

script = Script(None)

script.Show()


app.MainLoop()


省略部分界面的代码,点击按钮时出现错误提示:

TypeError: script() takes exactly 1 argument (2 given)

b = self.get_desktop()调用时传递了那两个参数?

非常谢谢。

...全文
697 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
The_Third_Wave 2014-10-11
  • 打赏
  • 举报
回复
首先提示的是
TypeError: script() takes exactly 1 argument (2 given)
而你问的这个get_desktop()函数只传递了1个参数,就是对象自身self 你问的和错误提示好像没有关系。 可能你该看看你的script函数调用是否正确。
xingyun1113 2014-10-11
  • 打赏
  • 举报
回复
  self.Bind(wx.EVT_BUTTON, self.script, self.m_button4)
调用是响应这个按键事件,这里传递了两个参数。 改为如下后正常了。
  def script(self,evt):
        b = self.get_desktop()
        print b
        #m_sctipt = open((self.get_desktop()+'\\'+self.m_textCtrl1.GetValue()+'.txt'),'w')
        #m_sctipt.close()
非常感谢。

37,720

社区成员

发帖
与我相关
我的任务
社区描述
JavaScript,VBScript,AngleScript,ActionScript,Shell,Perl,Ruby,Lua,Tcl,Scala,MaxScript 等脚本语言交流。
社区管理员
  • 脚本语言(Perl/Python)社区
  • IT.BOB
加入社区
  • 近7日
  • 近30日
  • 至今

试试用AI创作助手写篇文章吧