Issue
i am new in Python programming and I can not move forward because of that problem.
My code is above:
#!/usr/bin/python3
# -*- coding: utf-8 -*-
"""
spike 1
9.03.2012
Kevin
"""
import sys
from PySide.QtCore import *
from PySide.QtGui import *
class GuiRenamator(QWidget):
def __init__(self): # constructeur
super(GuiRenamator, self).__init__() # je ne sais pas ce que c'est
self.contenuGui()
def dialogTest(self):
dial_1 = QDialog()
dial_1.setWindowTitle("Voici ce qui est écrit")
text_dial_1 = QTextEdit()
vblay_dial = QVBoxLayout()
vblay_dial.addWidget(text_dial_1)
self.setLayout(vblay_dial)
# a bit of code
if contenuGui.chk_ancienNom.isChecked():
text_dial_1.append("- ajouter ancien nom")
if contenuGui.chk_increment.isChecked():
text_dial_1.append("- ajouter incrément")
if contenuGui.chk_dateCreation.isChecked():
text_dial_1.append("- ajouter date de création")
dial_1.show()
def contenuGui(self):
lbl_nomDossier = QLabel("Nom du dossier: ")
txt_nomDossier = QTextEdit()
btn_selecDossier = QPushButton("+")
chk_ancienNom = QCheckBox()
chk_increment = QCheckBox()
chk_dateCreation = QCheckBox()
btn_ok = QPushButton("OK")
**btn_ok.clicked.connect(dialogTest)**
lbl_log = QLabel("Logs")
txt_log = QTextEdit()
# Layouts
hblay_1 = QHBoxLayout()
hblay_1.addWidget(btn_selecDossier)
hblay_1.addWidget(lbl_nomDossier)
hblay_1.addWidget(txt_nomDossier)
flay_2 = QFormLayout()
flay_2.addRow("Ancien nom", chk_ancienNom)
flay_2.addRow("Incrément", chk_increment)
flay_2.addRow("Date de création", chk_dateCreation)
vblay_main = QVBoxLayout()
vblay_main.addLayout(hblay_1)
vblay_main.addLayout(flay_2)
vblay_main.addWidget(btn_ok)
vblay_main.addWidget(lbl_log)
vblay_main.addWidget(txt_log)
self.setLayout(vblay_main)
self.setGeometry(300, 300, 300, 150)
self.setWindowTitle("Ranamator")
self.show()
def main():
app = QApplication(sys.argv)
gui = GuiRenamator()
sys.exit(app.exec_())
if __name__ == '__main__':
main()
When I run the script, the following message appear:
Traceback (most recent call last):
File "./layout_spike_1.py", line 90, in <module>
main()
File "./layout_spike_1.py", line 86, in main
gui = GuiRenamator()
File "./layout_spike_1.py", line 20, in __init__
self.contenuGui()
File "./layout_spike_1.py", line 54, in contenuGui
btn_ok.clicked.connect(dialogTest)
NameError: global name 'dialogTest' is not defined
when I comment the line: btn_ok.clicked.connect(dialogTest)
It works fine but i Can not connect the QPushButton
to the dialogTest
method.
I thank you in advance.
Cheers,
Kevin
Solution
replace that line with btn_ok.clicked.connect(self.dialogTest)
Answered By - Ionut Hulub
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.