Issue
I wrote this codes:
import sys
import os
from PyQt5 import QtWidgets
class Notepad(QtWidgets.QWidget):
def __init__(self):
super().__init__()
self.init_ui()
def init_ui(self):
self.yazi_alani = QtWidgets.QTextEdit()
self.temizle = QtWidgets.QPushButton("Temizle")
self.kaydet = QtWidgets.QPushButton("Kaydet")
self.dosya_ac = QtWidgets.QPushButton("Dosya Aç")
v_box = QtWidgets.QVBoxLayout()
v_box.addWidget(self.yazi_alani)
v_box.addWidget(self.temizle)
v_box.addWidget(self.kaydet)
v_box.addWidget(self.dosya_ac)
self.setLayout(v_box)
self.setWindowTitle("Barış'ın Notepad Programı")
self.setGeometry(200,200,800,600)
self.temizle.clicked.connect(self.temizle)
self.kaydet.clicked.connect(self.kaydet)
self.dosya_ac.clicked.connect(self.dosya_ac)
self.show()
def temizle(self):
self.yazi_alani.clear()
def kaydet(self):
dosya_ismi = QtWidgets.QFileDialog.getSaveFileName(self,"Dosya Kaydet",os.getenv("HOME"))
with open (dosya_ismi[0],"w",encoding="utf-8") as file:
file.write(self.yazi_alani.toPlainText())
def dosya_ac(self):
dosya_ismi = QtWidgets.QFileDialog(self, "Dosya Aç", os.getenv("HOME"))
with open(dosya_ismi[0],"r",encoding="utf-8") as file:
self.yazi_alani.setText(file.read())
app = QtWidgets.QApplication(sys.argv)
pencere = Notepad()
sys.exit(app.exec())
I got this error:
Traceback (most recent call last):
File "C:/Users/noikp/Desktop/PyQt5 projem.py", line 41, in <module>
pencere = Pencere()
File "C:/Users/noikp/Desktop/PyQt5 projem.py", line 8, in __init__
self.init_ui()
File "C:/Users/noikp/Desktop/PyQt5 projem.py", line 28, in init_ui
self.temizle.clicked.connect(self.temizle)
TypeError: argument 1 has unexpected type 'QPushButton'
How can I solve this error? It may be good if you answer fast...
pythonerrors python error errors errorrr python3-x
Solution
You should rename your buttons or funcions. You've got here method Notepad.temizle() AND button Notepad.temizle So when you expect to send a message, instead you send a button, which is typeError Also I can see the same error with other methods
Answered By - Poweedlou
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.