我是python新手,帮我看看那里出错了

软件和网站开发以及相关技术探讨
回复
头像
Ragingflames
帖子: 89
注册时间: 2006-09-08 19:59
送出感谢: 0
接收感谢: 0

我是python新手,帮我看看那里出错了

#1

帖子 Ragingflames » 2008-09-28 11:29

代码: 全选

#!/usr/bin/env python
#-*-coding:utf-8-*-
# file: PyGTKButtonEvent.py
#
import pygtk
pygtk.require('2.0')
import gtk
class MyWindow():
	def __init__(self,title,width,height):
		self.window=gtk.Window()
		self.window.set_title(title)
		self.window.set_default_size(width,height)
		self.window.connect('destroy',lambda q: gtk.main_quit())
		hbox=gtk.HBox(False,20)
		self.button1=gtk.Button('Button1')
		self.button2=gtk.Button('Button2')
		self.button1.connect('clicked',self.OnButton,'Button1')
		self.button2.connect('clicked',self.OnButton,'Button2')
		hbox.pack_start(self.button1)
		hbox.pack_start(self.button2)
		self.window.add(hbox)
		hbox.show()
		self.button1.show()
		self.button2.show()
		self.window.show()
	def main(self):
		gtk.main()
	def Onbutton1(self,widget,data):
		self.button2.set_label('Quit')
	def OnButton2(self,widget,data):
		gtk.main_quit()
window=MyWindow('PyGTK',150,30)
window.main()
----------------------------------------------------------------------------------------
Traceback (most recent call last):
  File "D:\employment\python\PyGTKButtonEvent.py", line 32, in <module>
    window=MyWindow('PyGTK',150,30)
  File "D:\employment\python\PyGTKButtonEvent.py", line 17, in __init__
    self.button1.connect('clicked',self.OnButton,'Button1')
AttributeError: MyWindow instance has no attribute 'OnButton'
ALC655 SB450的声卡的福音请去我帖子

http://forum.ubuntu.org.cn/viewtopic.ph ... highlight=
头像
oneleaf
论坛管理员
帖子: 10235
注册时间: 2005-03-27 0:06
系统: Ubuntu 12.04
送出感谢: 7 次
接收感谢: 106 次

Re: 我是python新手,帮我看看那里出错了

#2

帖子 oneleaf » 2008-09-28 11:35

self.button1.connect('clicked',self.OnButton,'Button1')
self.button2.connect('clicked',self.OnButton,'Button2')
=>
self.button1.connect('clicked',self.OnButton1,'Button1')
self.button2.connect('clicked',self.OnButton2,'Button2')
头像
Ragingflames
帖子: 89
注册时间: 2006-09-08 19:59
送出感谢: 0
接收感谢: 0

Re: 我是python新手,帮我看看那里出错了

#3

帖子 Ragingflames » 2008-09-29 11:10

代码: 全选

#!/usr/bin/env python

#-*-coding:utf-8-*-

# file: PyGTKButtonEvent.py

#

import pygtk

pygtk.require('2.0')

import gtk

class MyWindow():

	def __init__(self,title,width,height):

		self.window=gtk.Window()

		self.window.set_title(title)

		self.window.set_default_size(width,height)

		self.window.connect('destroy',lambda q: gtk.main_quit())

		hbox=gtk.HBox(False,20)

		self.button1=gtk.Button('Button1')

		self.button2=gtk.Button('Button2')

		self.button1.connect('clicked',self.OnButton1,'Button1')

		self.button2.connect('clicked',self.OnButton2,'Button2')

		hbox.pack_start(self.button1)

		hbox.pack_start(self.button2)

		self.window.add(hbox)

		hbox.show()

		self.button1.show()

		self.button2.show()

		self.window.show()

	def main(self):

		gtk.main()

	def Onbutton1(self,widget,data):

		self.button2.set_label('Quit')

	def OnButton2(self,widget,data):

		gtk.main_quit()

window=MyWindow('PyGTK',150,30)

window.main()
------------------------------------------------------
在ubuntu 8.04下是
: 没有该文件或目录on
ALC655 SB450的声卡的福音请去我帖子

http://forum.ubuntu.org.cn/viewtopic.ph ... highlight=
回复

回到 “软件/网站开发”