PyQt5 when I click button it close window itself

+3 votes

PyQt5, when I click button, it close window itself.

Hi, I am very new to PyQt5. if this it too basic question. 

please give me some howtouse url. so I can learn my self.

import sys, io
from PyQt5.QtWidgets import *
from PyQt5.QtCore import *
from PyQt5 import uic
from tag_test import Ui_MainWindow
import pymysql
pymysql.install_as_MySQLdb()
import MySQLdb
from sqlalchemy import create_engine

sys.stdout = io.TextIOWrapper(sys.stdout.detach(), encoding = 'utf-8')
sys.stderr = io.TextIOWrapper(sys.stderr.detach(), encoding = 'utf-8')

class Main(QMainWindow, Ui_MainWindow):
    def __init__(self):
        super().__init__()
        self.setupUi(self)
        self.initSignal()

    def initSignal(self):
        self.pushButton_7.clicked.connect(self.inputAdinfo)
        self.pushButton_8.clicked.connect(self.inputKeyword)

    @pyqtSlot()
    def inputAdinfo(self):
        self.ad_productN = self.lineEdit.text()
        self.ad_camN = self.lineEdit_2.text()
        print(self.ad_productN, self.ad_camN)

    @pyqtSlot()
    def inputKeyword(self):
        self.Keywords = self.plainTextEdit.text()
        print(self.Keywords)

# print(self.ad_productN, self.ad_camN , self.Keywords)

if __name__ == "__main__":
    app = QApplication(sys.argv)
    window = Main()
    window.show()
    app.exec_()

this is my code.

i tested it with 

   print('test')

at both of pyqtSlot and it worked fine. 

so I thought signal and slot are connected.

but when i put second def

def inputKeyword(self):
        self.Keywords = self.plainTextEdit.text()
        print(self.Keywords)

as soon as I click the button, it close itself.

how can i fix this?

Dec 9, 2019 in Python by 의철
• 150 points
3,784 views
If you run it from the terminal or cmd it will show an error which will give a clue as to where the problem is

No answer to this question. Be the first to respond.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.

Related Questions In Python

0 votes
0 answers

I am trying to click the button but it is not working and it is drop list ..

<a class="quickreports btn btn3d tbbtn" href="javascript:" style="position:static" ...READ MORE

Dec 2, 2019 in Python by anonymous
• 120 points
798 views
+1 vote
0 answers

How to close a window, and then reinitialize it using PyQt

There is a button "btn_closeWin_and_reinit"  in the ...READ MORE

Jul 10, 2019 in Python by marceepoo
• 130 points

edited Jul 22, 2019 by Kalgi 7,441 views
0 votes
0 answers

For some reason i cannot click on this element/button and have been trying for hours PLEASE HELP!!

from selenium import webdriver from selenium.webdriver.chrome.options import Options from ...READ MORE

Jun 18, 2020 in Python by Justin
• 140 points

reshown Jun 18, 2020 by Sirajul 767 views
0 votes
1 answer

How do I call a Django function on button click?

Hello @kartik, There are 2 possible solutions that ...READ MORE

answered Jun 23, 2020 in Python by Niroj
• 82,840 points
60,893 views
0 votes
1 answer

When I create and remove files rapidly on windows using python I get WindowsError (Error 5)

Here's the short answer: disable any antivirus or ...READ MORE

answered Aug 31, 2018 in Python by charlie_brown
• 7,720 points
1,917 views
0 votes
2 answers
+1 vote
2 answers

how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

answered Jul 7, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 4,440 views
0 votes
1 answer
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP