如何通过按钮获得特定的输出

时间:2019-06-26 18:17:26

标签: python parsing tkinter

我做了一个按钮。我想尝试启动某个功能,用户输入“ x”并按下按钮。这是我到目前为止的代码,但是我不确定该怎么做

self.submit = Button(text='Submit', font_size= 35)
    self.submit.bind(on_press = self.pressed)   
    self.add_widget(self.submit)   

def pressed(self, instance):
    for x in soup.select('.genre'):
        print(x.text)

1 个答案:

答案 0 :(得分:0)

使用command选项作为按钮:

    self.submit = Button(self, text='Submit', font_size=35, command=self.pressed)
    self.submit.grid()

def pressed(self, event):
    # Do stuff here.

这样,每次单击该按钮,它将运行指定的功能。

有关更多信息,请单击here