Please help!
-
Dear all,
I am a new in python programming QT. I am trying to make a small program to download videos from Youtube but I have small issue in it.The program design as follows:
First line "lineEdit" for url link.
Second line "lineEdit_2" for save as in my desktop.
Third line "pushbutton" for click to download.Everything is working smoothly. What I want is when I press in the download button (Pushbutton) through a message box: "The link is empty" by checking the fields "lineEdit" or "lineEdit_2" if it is blank (empty) or not.
What I have tried this statement,
if len(self.lineEdit.text()) == 0 and len(self.lineEdit_2.text()) == 1:
QMessageBox.information(self, "Error", "The link is empty")The code
###PyQt5 && Python 3.4####
#class self.Handel_Buttons() self.Handel_Browse() def Handel_Buttons(self): self.pushButton.clicked.connect(self.Download) def Handel_Browse(self): pass def Download(self): url= self.lineEdit.text() save_location = self.lineEdit_2.text() # First check if len(self.lineEdit.text()) == 0 and len(self.lineEdit_2.text()) == 1: QMessageBox.information(self, "Error", "The link is empty") try: urllib.request.urlretrieve(url, save_location) except Exception: QMessageBox.warning(self , "Download Error" , "The Download is Failed") return QMessageBox.Information(self , "Download Completed" , "The Download is Finished")###End of the code###
But no success. Any ideas.
Many thanks,
-
Dear all,
I am a new in python programming QT. I am trying to make a small program to download videos from Youtube but I have small issue in it.The program design as follows:
First line "lineEdit" for url link.
Second line "lineEdit_2" for save as in my desktop.
Third line "pushbutton" for click to download.Everything is working smoothly. What I want is when I press in the download button (Pushbutton) through a message box: "The link is empty" by checking the fields "lineEdit" or "lineEdit_2" if it is blank (empty) or not.
What I have tried this statement,
if len(self.lineEdit.text()) == 0 and len(self.lineEdit_2.text()) == 1:
QMessageBox.information(self, "Error", "The link is empty")The code
###PyQt5 && Python 3.4####
#class self.Handel_Buttons() self.Handel_Browse() def Handel_Buttons(self): self.pushButton.clicked.connect(self.Download) def Handel_Browse(self): pass def Download(self): url= self.lineEdit.text() save_location = self.lineEdit_2.text() # First check if len(self.lineEdit.text()) == 0 and len(self.lineEdit_2.text()) == 1: QMessageBox.information(self, "Error", "The link is empty") try: urllib.request.urlretrieve(url, save_location) except Exception: QMessageBox.warning(self , "Download Error" , "The Download is Failed") return QMessageBox.Information(self , "Download Completed" , "The Download is Finished")###End of the code###
But no success. Any ideas.
Many thanks,
@monamour said in Please help!:
if len(self.lineEdit.text()) == 0 and len(self.lineEdit_2.text()) == 1
Why do you have
len(self.lineEdit_2.text()) == 1? Why 1?
Also you can use http://doc.qt.io/qt-5/qstring.html#lengthif not self.lineEdit.text().empty() and not self.lineEdit_2.text().empty: QMessageBox.information(self, "Error", "The link is empty") -
@monamour said in Please help!:
if len(self.lineEdit.text()) == 0 and len(self.lineEdit_2.text()) == 1
Why do you have
len(self.lineEdit_2.text()) == 1? Why 1?
Also you can use http://doc.qt.io/qt-5/qstring.html#lengthif not self.lineEdit.text().empty() and not self.lineEdit_2.text().empty: QMessageBox.information(self, "Error", "The link is empty") -
-
if not self.lineEdit.text().empty() and not self.lineEdit_2.text().empty(): QMessageBox.information(self, "Error", "The link is empty") -
-
@monamour OK. It returns a Python string. Then use your approach with len(...), but fix that == 1
-
@jsulm The problem has been solved after I fixed the "== 1".
Many thanks. I am so appreciated for your help.
@monamour if your issue is solved, please don't forget to mark your post as such! Thanks
-
@monamour if your issue is solved, please don't forget to mark your post as such! Thanks
@Pablo-J.-Rogina Done. Thanks.