Answer the question
In order to leave comments, you need to log in
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
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()
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 questionAsk a Question
731 491 924 answers to any question