我有一个包含两个按钮和一个框架的网页。在该框架内,将显示一个网页。我正在尝试让按钮A在框架中穿url '/AAA‘,而按钮B在框架中穿url '/BBB’。我该怎么做呢?
这就是我所拥有的:
class ImageButton(SimplePanel):
def __init__(self, image_location):
'''(None, str) -> None'''
SimplePanel.__init__(self)
img = Image(image_location, StyleName='rangler')
img.addClickListener(getattr(self, "onImageClick"))
self.add(img)
def onImageClick(self, sender=None):
pass
#This is where I need help!?
class QAFrame(SimplePanel):
def __init__(self, current_url):
SimplePanel.__init__(self)
frame = Frame(current_url,
Width="200%",
Height="650px")
self.add(frame)
def caption():
style_sheet = HTML("""<link rel='stylesheet' href='about_us.css'>""")
srah_pic = ImageButton("Steve.jpg")
fl_pic = ImageButton("Fraser.jpg")
horizontal = HorizontalPanel()
vertical = VerticalPanel()
vertical.add(srah_pic)
vertical.add(fl_pic)
horizontal.add(vertical)
QAFrame('Fraser_qa.htm')
QAFrame('Steve_qa.htm')
horizontal.add(QAFrame('Steve_qa.htm'))
RootPanel().add(horizontal)发布于 2012-06-22 23:51:57
基本上,
您需要.addClickListener到您的按钮,并且作为一个参数,您希望传入一个处理程序,该处理程序将在单击按钮时执行所需的任务。
真正让我困惑的一件事是,我不能将参数传递给我的处理程序。但是,对象"sender“会自动与处理程序一起传入。您可以尝试搜索发件人属性以查找所需的信息。
class ImageButton(SimplePanel):
def __init__(self, image_location, css_style):
'''(None, str, str) -> None'''
SimplePanel.__init__(self)
self.image_location = image_location
img = Image(self.image_location, StyleName= css_style)
img.addClickListener(Cool) # Cool is the name of my handler function
self.add(img)
def Cool(sender): # You can do whatever you want in your handler function.
# I am changing the url of a frame
# It is a little-medium "Hacky"
if sender.getUrl()[-9:] == 'Steve.jpg':
iframe.setUrl('Fraser_qa.htm')
else:
iframe.setUrl('Steve_qa.htm')发布于 2012-07-27 16:37:59
我将扩展我的ImageButton类以支持传入您想要显示的网页的URL。在__init__函数中,您可以将该URL存储在实例属性中。
您应该将clickhandler转换为一个实例方法,该方法可以访问实例变量,该变量保存所需页面的URL。
我缺乏明确的Python知识来提供代码示例。希望你还能理解这个概念。
https://stackoverflow.com/questions/11130927
复制相似问题