Probleme de fonctionnement du signal avec pyqt5
bonjour et merci de m'avoir accepté parmi vous. Je suis nouveau dans le forum et nouveau dans la programmation python.
J'ai un code qui doit tester le fonctionnement d'un signal. En fait sur la fenetre graphique, je dois dois cliquer sur un bouton crée à partir d'une classe comme l'indique mon code pour récupérer le contenu de la QLineEdit et afficher dans un QLabel. Mais la fenetre s'affiche bien mais aucune action lorsque je clique sur le bouton. Quelqu'un pourrait il m'aider pour me souhaiter la bienvenue? merci.
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
| import sys
from PyQt5.QtWidgets import*
from PyQt5.QtCore import*
from PyQt5.QtGui import*
########################################################################################
class MyButton1(QPushButton):
def __init__(self,text=None,x=0,y=0,width=10,height=5):
super().__init__()
self.text = text
self.x = x
self.y = y
self.width = width
self.height = height
btn = QPushButton(fen)
btn.setText(self.text)
btn.setGeometry(self.x,self.y,self.width,self.height)
btn.setStyleSheet("background-color:pink; \
color:Blue; \
border-width:2px; \
border-radius:20px; \
border-color:blue; \
border-style:solid; \
font: bold 28px;");
def copy():
t = textbox.text()
lbl.setText(t)
if __name__=="__main__":
app = QApplication(sys.argv)
fen = QWidget()
btn = MyButton1("Ouvrir", 100, 250, 250, 50)
btn.clicked.connect(copy)
textbox = QLineEdit(fen)
textbox.setGeometry(100,100,250,40)
textbox.setStyleSheet("background-color: ivory; \
color:blue; \
font: bold 25px; \
border-style: solid; \
border-width:1px; \
border-radius: 5px; \
border-color:blue; ");
lbl = QLabel(fen)
lbl.setGeometry(100, 150, 250, 40)
lbl.setText("merci")
lbl.show()
fen.show()
sys.exit(app.exec_()) |