0

2 つのボタンとフレームを含む Web ページがあります。フレーム内に Web ページが表示されます。フレーム内のボタン 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)
4

2 に答える 2

1

基本的、

ボタンに .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-06-22T15:51:57.447 に答える
0

ImageButton クラスを拡張して、表示する Web ページへの URL の受け渡しをサポートします。関数では、__init__その URL をインスタンス プロパティに格納できます。

clickhandler をインスタンス メソッドにする必要があります。このメソッドは、目的のページへの URL を保持するインスタンス変数にアクセスできます。

コード例を提供するための決定的な Python の知識が不足しています。コンセプトを理解していただければ幸いです。

于 2012-07-27T08:37:58.923 に答える