Pyqt5 : How To Complete This Code In The Function 'dollar()'
Please help me to complete this code. I want make a text editor and when I give a number in the input dialog, some text or some symbol or some numbers insert to my text lines to nu
Solution 1:
You are replacing the the text in your text edit at each iteration. The easiest (clearer) way to do that, would be to generate all your lines before trying to add it to the text edit.
For example:
def dollar(self):
text_1_int , ok = QInputDialog.getInt(self,'HowMany?','Enter How Many dollar do you want ?')
if not ok:
return
try:
current_lines = self.te.toPlainText().split('\n')
new_lines = list()
for dollar_counter in range(1, text_1_int + 1):
word = '$' * dollar_counter
new_lines += [text + word for text in current_lines]
self.te.setPlainText("\n".join(new_lines))
except:
error_msg = QMessageBox()
error_msg.setIcon(QMessageBox.Critical)
error_msg.setText('Please Enter Just Number')
error_msg.setWindowTitle("Error")
error_msg.exec_()
If I enter 3 in the text input:
Btw, the dollar_counter
increment is useless: it will be handled by the for
loop.
Post a Comment for "Pyqt5 : How To Complete This Code In The Function 'dollar()'"