I
I
Ilya1992018-06-16 12:40:37
Python
Ilya199, 2018-06-16 12:40:37

Is it possible to set a function for a button without pressing it?

The bottom line is: I click on the button, then a function occurs (on_press = self.test_press - for example), in which I, for example, make a new text for another button. Is it possible?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
D
Dimonchik, 2018-06-16
@dimonchik2013

Yes

A
Alexander, 2018-06-16
@sanya84

import sys
from PyQt5.QtWidgets import *


class Example(QWidget):
    def __init__(self):
        super().__init__()
        self.resize(180, 40)
        self.setWindowTitle("Пример")

        self.button = QPushButton('изменить надпись нижней кнопки', self)
        self.button.clicked.connect(self.function)
        self.button_2 = QPushButton('Hello user!', self)
        self.button_2.setGeometry(0, 20, 180, 25)

    def function(self):
        self.button_2.setText("Привет пользователь!")

def main():
    app = QApplication(sys.argv)
    window = Example()
    window.show()
    sys.exit(app.exec_())

if __name__ == '__main__':
    main()

A
Albert, 2018-11-17
@bigburn

If it is still relevant, then, for example, like this:

import kivy
from kivy.app import App
from kivy.lang import Builder

KV = """
BoxLayout
    Button
        text: "click me!"
        on_press: b2.text='thank you!'
    Button
        id: b2
"""

class MyApp(App):
    def build(self):
        self.root = Builder.load_string(KV)

MyApp().run()

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question