@Leog
Любитель Python

Почему не закрывается Qfiledialog после нажатия кнопки ok?

def openFileNameD(self):
        
        fileName=QtWidgets.QFileDialog.getOpenFileName()[0]
        
       
        return fileName
    # функция для проверки соединения с бд и в ней будет вызов функции для выбора файла бд 
    def cheak_conection_with_db(self, adress_file, adress_of_data_base,rewritenum):
        try:
            dburi = 'file:{}?mode=rw'.format(pathname2url(adress_of_data_base))
            conn = sqlite3.connect(dburi, uri=True)
            print('yes')
            return adress_of_data_base
        except sqlite3.OperationalError:
            print('no')
            #=r'E:\Myproject\New_Hotel_Interface\OB_DB.sqlite'
            a =self.openFileNameD()
            if rewritenum==0:
                with open(adress_file, 'w'):
                 pass
                file= open(adress_file,'w')
                file.write(a[0])
                file.close()
                return a[0]
            else:
                return a[0] 
    #функция которая отдает адрес бд  из файла на проверку конекта  в def cheak_conection_with_db и после в миксер запросов
    # adress_file -  адрес текстового файла , adress_of_data_base - адрес базы данных ,rewritenum - переменная для перезаписи адреса в бд 
    def adressmaker(self):
        adress_file=os.path.abspath('form.py')
        adress_file=adress_file.replace('form.py','')
        adress_file=adress_file+'myadress.txt'
        adress_of_data_base=''
        if os.path.isfile(adress_file) is True:
           file=open(adress_file,'r')
           adress_of_data_base=file.readline()
           file.close()
           ##################################################
           if not adress_of_data_base:
               adress_of_data_base=self.openFileNameD()
           ##################################################
           return self.cheak_conection_with_db(adress_file,adress_of_data_base,0)
        else:
            file=open(adress_file,'w')
            adress_of_data_base=adress_file.replace('myadress.txt','OB_DB.sqlite')
            adress_of_data_base=self.cheak_conection_with_db(adress_file,adress_of_data_base,1)
            file.write(adress_of_data_base)
            file.close()
            return adress_of_data_base

Выше указаны три функции отвечающие за соединения бд с программой . QFileDialog нужен для выбора файла бд . Но Он не закрывается при нажатии ок . А после нажатия отмена , появляется сообщение об отсутствии таблиц в бд .
Предполагаю что проблема связанна с sys.exit() но как его правильно вставить что-бы не закрылись другие окна не имею представления
  • Вопрос задан
  • 89 просмотров
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы