i am currently working on this gui project. and i create a settings window but i cant make it close after pushing the buttons. i tried use self.close(), self.accept(), self.reject() methods. When i click the button nothing happens. Here is my code, which is simplified :
from PyQt5.QtWidgets import (QLineEdit, QWidget, QMenu, QMenuBar, QAction,
QMainWindow, QApplication, QDialog, QPushButton, QVBoxLayout)
from PyQt5.QtCore import QSize, QRect, QMetaObject, QCoreApplication, QObject, Qt
class Ui_Dialog(QDialog):
def __init__(self):
super(Ui_Dialog, self).__init__()
def setupUi(self, Dialog):
Dialog.setObjectName("Dialog")
Dialog.resize(100, 100)
self.verticalLayout= QVBoxLayout(Dialog)
self.lineEdit = QLineEdit(Dialog)
self.lineEdit.setObjectName("lineEdit")
self.verticalLayout.addWidget(self.lineEdit)
self.pushButton = QPushButton(Dialog)
self.pushButton.setObjectName("pushButton")
self.verticalLayout.addWidget(self.pushButton)
self.pushButton_2 = QPushButton(Dialog)
self.pushButton_2.setObjectName("pushButton_2")
self.verticalLayout.addWidget(self.pushButton_2)
self.pushButton.clicked.connect(self.close)
self.pushButton_2.clicked.connect(self.save)
self.retranslateUi(Dialog)
QMetaObject.connectSlotsByName(Dialog)
def save(self):
global setting
setting = self.lineEdit.text()
self.done(1)
self.accept()
self.deleteLater()
self.destroy()
self.reject()
self.close()
def retranslateUi(self, Dialog):
_translate = QCoreApplication.translate
Dialog.setWindowTitle(_translate("Dialog", "Settings"))
self.pushButton_2.setText(_translate("Dialog", "Save"))
self.pushButton.setText(_translate("Dialog", "Cancel"))
class Ui_MainWindow(QObject):
def setupUi(self, MainWindow):
MainWindow.setObjectName("MainWindow")
MainWindow.resize(1250, 609)
MainWindow.setMinimumSize(QSize(833, 600))
self.centralWidget = QWidget(MainWindow)
MainWindow.setCentralWidget(self.centralWidget)
self.centralWidget.setObjectName("centralwidget")
self.menubar = QMenuBar(MainWindow)
self.menubar.setGeometry(QRect(0, 0, 906, 21))
self.menubar.setObjectName("menubar")
self.menuOptions = QMenu(self.menubar)
self.menuOptions.setObjectName("menuOptions")
MainWindow.setMenuBar(self.menubar)
self.actionSettings = QAction(MainWindow)
self.actionSettings.setObjectName("actionSettings")
self.menuOptions.addAction(self.actionSettings)
self.menubar.addAction(self.menuOptions.menuAction())
self.actionSettings.triggered.connect(self.preferences)
self.retranslateUi(MainWindow)
QMetaObject.connectSlotsByName(MainWindow)
def retranslateUi(self, MainWindow):
_translate = QCoreApplication.translate
MainWindow.setWindowTitle(_translate("MainWindow", "closinDialogSample"))
self.menuOptions.setTitle(_translate("MainWindow", "Options"))
self.actionSettings.setText(_translate("MainWindow", "Settings"))
def preferences(self):
self.preferences_dialog = QDialog()
self.preferences_dialog.ui = Ui_Dialog()
self.preferences_dialog.ui.setupUi(self.preferences_dialog)
self.preferences_dialog.setAttribute(Qt.WA_DeleteOnClose)
self.preferences_dialog.setModal(True)
self.preferences_dialog.show()
if __name__ == "__main__":
import sys
app = QApplication(sys.argv)
MainWindow = QMainWindow()
ui = Ui_MainWindow()
ui.setupUi(MainWindow)
MainWindow.show()
sys.exit(app.exec_())
Thank you for reading.
Related
I tried to use the mutex. Why did it automatically stop without an error.
Running will stop automatically after a while
This is my code, which can be run directly. Please help me to see what the problem is
Is my method wrong? Is there a better way to achieve it? I don't want my interface to get stuck
`
import time
from PyQt5 import QtWidgets, QtCore
from PyQt5.QtCore import QWaitCondition, QMutex
from PyQt5.QtWidgets import QMainWindow, QMessageBox, QApplication, QDesktopWidget
from PyQt5.QtCore import pyqtSignal
import sys
from PyQt5.QtCore import QThread
class Ui_MainWindow(object):
def setupUi(self, MainWindow):
MainWindow.setObjectName("MainWindow")
MainWindow.resize(800, 600)
self.centralwidget = QtWidgets.QWidget(MainWindow)
self.centralwidget.setObjectName("centralwidget")
self.horizontalLayout = QtWidgets.QHBoxLayout(self.centralwidget)
self.horizontalLayout.setObjectName("horizontalLayout")
self.pushButton = QtWidgets.QPushButton(self.centralwidget)
self.pushButton.setObjectName("pushButton")
self.horizontalLayout.addWidget(self.pushButton)
self.label = QtWidgets.QLabel(self.centralwidget)
self.label.setObjectName("label")
self.horizontalLayout.addWidget(self.label)
self.pushButton_2 = QtWidgets.QPushButton(self.centralwidget)
self.pushButton_2.setObjectName("pushButton_2")
self.horizontalLayout.addWidget(self.pushButton_2)
MainWindow.setCentralWidget(self.centralwidget)
self.menubar = QtWidgets.QMenuBar(MainWindow)
self.menubar.setGeometry(QtCore.QRect(0, 0, 800, 23))
self.menubar.setObjectName("menubar")
MainWindow.setMenuBar(self.menubar)
self.statusbar = QtWidgets.QStatusBar(MainWindow)
self.statusbar.setObjectName("statusbar")
MainWindow.setStatusBar(self.statusbar)
self.retranslateUi(MainWindow)
QtCore.QMetaObject.connectSlotsByName(MainWindow)
def retranslateUi(self, MainWindow):
_translate = QtCore.QCoreApplication.translate
MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow"))
self.pushButton.setText(_translate("MainWindow", "PushButton"))
self.label.setText(_translate("MainWindow", "TextLabel"))
self.pushButton_2.setText(_translate("MainWindow", "stop"))
class MainWindow(QMainWindow):
def __init__(self):
super().__init__()
self.ui = Ui_MainWindow()
self.ui.setupUi(self)
self.__init2__()
def __init2__(self):
self.search_running = False
self.ui.pushButton.clicked.connect(self.search)
self.ui.pushButton_2.clicked.connect(self.stop_search)
def stop_search(self):
if self.search_running:
reply = QMessageBox.information(self, 'notice', 'Do you want to stop searching?',
QMessageBox.Yes | QMessageBox.Cancel)
if reply == QMessageBox.Yes:
self.search_thread.terminate()
self.__thread.resume()
self.search_running = False
self.ui.pushButton.setEnabled(True)
else:
QMessageBox.information(self, 'tip', 'no search!', QMessageBox.Ok)
def search(self):
if not self.search_running:
self.search_running = True
self.ui.pushButton.setEnabled(False)
self.search_thread = Search_Thread()
self.search_thread.trigger.connect(lambda i: self.c(i))
self.search_thread.complete.connect(self.search_complete)
self.search_thread.start()
def c(self, i):
self.ui.label.setText(str(i))
self.search_thread.resume()
def search_complete(self):
self.__thread.resume()
self.search_running = False
self.ui.pushButton.setEnabled(True)
class Search_Thread(QThread):
trigger = pyqtSignal(int)
complete = pyqtSignal()
mutex = QMutex()
cond = QWaitCondition()
def __init__(self):
super().__init__()
def run(self):
self.mutex.lock()
for i in range(10000):
for j in range(10000):
print(j)
for k in range(10000):
# time.sleep(0.1)
self.trigger.emit(i + j + k)
# time.sleep(0.1)
self.cond.wait(self.mutex)
self.complete.emit()
self.mutex.unlock()
def resume(self):
self.cond.wakeAll()
if __name__ == '__main__':
app = QApplication(sys.argv)
window = MainWindow()
screen = QDesktopWidget().screenGeometry()
height = 100
width = 300
window.setGeometry(int((screen.width() - width) / 2), int((screen.height() - height) / 2), width, height)
window.setWindowTitle("test")
window.show()
sys.exit(app.exec())
`
help me,How to improve the code so that it does not stop automatically
This question already has an answer here:
PyQt4 - Dragging and dropping files into QPushButton
(1 answer)
Closed 3 years ago.
I want to drag plain text from lineEdit widget to drop pushbutton label in PyQt5. Here is the code:
from PyQt5 import QtCore, QtGui, QtWidgets
import sys
class Ui_MainWindow(object):
def setupUi(self, MainWindow):
MainWindow.setObjectName("MainWindow")
MainWindow.resize(873, 663)
self.centralwidget = QtWidgets.QWidget(MainWindow)
self.centralwidget.setObjectName("centralwidget")
self.pushButton2= QtWidgets.QPushButton(self.centralwidget)
self.pushButton2.setGeometry(QtCore.QRect(280, 40, 93, 28))
self.pushButton2.setObjectName("pushButton2")
self.pushButton2.setAcceptDrops(True)
self.lineEdit = QtWidgets.QLineEdit(self.centralwidget)
self.lineEdit.setGeometry(QtCore.QRect(120, 200, 113, 22))
self.lineEdit.setObjectName("lineEdit")
MainWindow.setCentralWidget(self.centralwidget)
self.lineEdit.setDragEnabled(True)
self.retranslateUi(MainWindow)
class pushButton2(QtWidgets.QPushButton):
def __init__(self, title, parent):
super().__init__(title, parent)
self.setAcceptDrops(True)
def dragEnterEvent(self, event):
if event.mimeData().hasFormat('text/plain'):
event.accept()
else:
event.ignore()
def dropEvent(self, event):
self.setText(event.mimeData().text())
def retranslateUi(self, MainWindow):
_translate = QtCore.QCoreApplication.translate
MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow"))
self.pushButton2.setText(_translate("MainWindow", "PushButton2"))
self.lineEdit.setText(_translate("MainWindow", "k"))
if __name__ == "__main__":
if not QtWidgets.QApplication.instance():
app = QtWidgets.QApplication(sys.argv)
else:
app = QtWidgets.QApplication.instance()
MainWindow = QtWidgets.QMainWindow()
ui = Ui_MainWindow()
ui.setupUi(MainWindow)
MainWindow.show()
app.exec_()
I would expect to drag text from lineEdit to show as pushbutton label but it did not accepted , why ?
Try it:
import sys
from PyQt5 import QtCore, QtGui, QtWidgets
# class pushButton2(QtWidgets.QPushButton):
class PushButton(QtWidgets.QPushButton): # <---
def __init__(self, title, parent):
super().__init__(title, parent)
self.setAcceptDrops(True)
def dragEnterEvent(self, e):
if e.mimeData().hasFormat('text/plain'):
e.accept()
else:
e.ignore()
def dropEvent(self, e):
self.setText(e.mimeData().text())
class Ui_MainWindow(object):
def setupUi(self, MainWindow):
MainWindow.setObjectName("MainWindow")
MainWindow.resize(873, 663)
self.centralwidget = QtWidgets.QWidget(MainWindow)
self.centralwidget.setObjectName("centralwidget")
# self.pushButton2= QtWidgets.QPushButton(self.centralwidget)
self.pushButton2 = PushButton("PushButton2", self.centralwidget) # <---
self.pushButton2.setGeometry(QtCore.QRect(120, 140, 93, 28))
self.pushButton2.setObjectName("pushButton2")
# self.pushButton2.setAcceptDrops(True)
self.lineEdit = QtWidgets.QLineEdit(self.centralwidget)
self.lineEdit.setGeometry(QtCore.QRect(120, 200, 113, 22))
self.lineEdit.setObjectName("lineEdit")
MainWindow.setCentralWidget(self.centralwidget)
self.lineEdit.setDragEnabled(True)
self.retranslateUi(MainWindow)
def retranslateUi(self, MainWindow):
_translate = QtCore.QCoreApplication.translate
MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow"))
self.pushButton2.setText(_translate("MainWindow", "PushButton2"))
self.lineEdit.setText(_translate("MainWindow", "k"))
class ExampleApp(QtWidgets.QMainWindow, Ui_MainWindow):
def __init__(self):
super().__init__()
self.setupUi(self)
if __name__ == "__main__":
if not QtWidgets.QApplication.instance():
app = QtWidgets.QApplication(sys.argv)
else:
app = QtWidgets.QApplication.instance()
MainWindow = ExampleApp()
MainWindow.show()
app.exec_()
I show a dialog from main. In the dialog, I change the value of a global variable. But after the dialog closes, the global variable does not change the value.
I use PyQt5. Here is the code I call the dialog and change the variable value. I use varA to store dialog result.
def Clicked(self):
global varA
dialog = clssDialog()
dialog.exec_()
print(varA)
dialog ui
class clssDialog(QDialog):
def __init__(self):
super(clssDialog, self).__init__()
#some code
In dialog. I use:
def btnClosed(self):
global varA
varA=value
self.close()
Edit: Full code
main.py
from PyQt5 import QtCore, QtGui, QtWidgets
from dialog import *
class Ui_MainWindow(object):
def setupUi(self, MainWindow):
MainWindow.setObjectName("MainWindow")
MainWindow.resize(219, 62)
self.centralwidget = QtWidgets.QWidget(MainWindow)
self.centralwidget.setObjectName("centralwidget")
self.verticalLayout = QtWidgets.QVBoxLayout(self.centralwidget)
self.verticalLayout.setObjectName("verticalLayout")
self.pushButton = QtWidgets.QPushButton(self.centralwidget)
self.pushButton.setObjectName("pushButton")
self.pushButton.clicked.connect(self.Clicked)
self.verticalLayout.addWidget(self.pushButton)
MainWindow.setCentralWidget(self.centralwidget)
self.statusbar = QtWidgets.QStatusBar(MainWindow)
self.statusbar.setObjectName("statusbar")
MainWindow.setStatusBar(self.statusbar)
self.retranslateUi(MainWindow)
QtCore.QMetaObject.connectSlotsByName(MainWindow)
def retranslateUi(self, MainWindow):
_translate = QtCore.QCoreApplication.translate
MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow"))
self.pushButton.setText(_translate("MainWindow", "Open form"))
def Clicked(self):
global varA
varA=""
dialog = clssDialog()
dialog.exec_()
print("value: " + varA)
if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
MainWindow = QtWidgets.QMainWindow()
ui = Ui_MainWindow()
ui.setupUi(MainWindow)
MainWindow.show()
sys.exit(app.exec_())
dialog.py
from PyQt5 import QtCore, QtGui, QtWidgets
from PyQt5.QtWidgets import *
from PyQt5.QtGui import *
class clssDialog(QDialog):
def __init__(self):
super(clssDialog, self).__init__()
self.verticalLayout = QtWidgets.QVBoxLayout(self)
self.verticalLayout.setObjectName("verticalLayout")
self.pushButton = QtWidgets.QPushButton(self)
self.pushButton.setObjectName("pushButton")
self.pushButton.clicked.connect(self.btnClosed)
self.verticalLayout.addWidget(self.pushButton)
self.setWindowTitle("Dialog")
self.pushButton.setText("Close")
def btnClosed(self):
global varA
varA="123"
self.close()
It is not recommended to change the file created in QT Designer.
It is not necessary or advisable to use global variables. I also recommend reading Why are global variables evil?
Try it:
import sys
from PyQt5 import QtCore, QtGui, QtWidgets
from PyQt5.QtWidgets import *
from PyQt5.QtGui import *
#from dialog import *
class Ui_MainWindow(object):
def setupUi(self, MainWindow):
MainWindow.setObjectName("MainWindow")
MainWindow.resize(219, 62)
self.centralwidget = QtWidgets.QWidget(MainWindow)
self.centralwidget.setObjectName("centralwidget")
self.verticalLayout = QtWidgets.QVBoxLayout(self.centralwidget)
self.verticalLayout.setObjectName("verticalLayout")
self.pushButton = QtWidgets.QPushButton(self.centralwidget)
self.pushButton.setObjectName("pushButton")
self.pushButton.clicked.connect(self.Clicked)
self.verticalLayout.addWidget(self.pushButton)
MainWindow.setCentralWidget(self.centralwidget)
self.statusbar = QtWidgets.QStatusBar(MainWindow)
self.statusbar.setObjectName("statusbar")
MainWindow.setStatusBar(self.statusbar)
self.retranslateUi(MainWindow)
QtCore.QMetaObject.connectSlotsByName(MainWindow)
def retranslateUi(self, MainWindow):
_translate = QtCore.QCoreApplication.translate
MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow"))
self.pushButton.setText(_translate("MainWindow", "Open form"))
# def Clicked(self):
# global varA
# varA=""
# dialog = ClssDialog()
# dialog.exec_()
# print("value: " + varA)
class ClssDialog(QDialog):
# def __init__(self):
# super(ClssDialog, self).__init__()
def __init__(self, parent=None):
super(ClssDialog, self).__init__(parent)
self.parent = parent
self.verticalLayout = QtWidgets.QVBoxLayout(self)
self.verticalLayout.setObjectName("verticalLayout")
self.pushButton = QtWidgets.QPushButton(self)
self.pushButton.setObjectName("pushButton")
self.pushButton.clicked.connect(self.btnClosed)
self.verticalLayout.addWidget(self.pushButton)
self.setWindowTitle("Dialog")
self.pushButton.setText("Close")
def btnClosed(self):
# global varA
self.parent.varA = "123"
self.close()
class ExampleApp(QtWidgets.QMainWindow, Ui_MainWindow):
def __init__(self):
super().__init__()
self.setupUi(self)
self.varA = ""
def Clicked(self):
# global varA
# varA=""
dialog = ClssDialog(self)
dialog.exec_()
print("value: " + self.varA)
if __name__ == "__main__":
app = QApplication(sys.argv)
view = ExampleApp()
view.show()
sys.exit(app.exec_())
I would like to embed a graphic from Matplotlib into an existing GUI containing a Widget and a PushButton developed from QtDesigner and PyQt5. I can embed the graphic but can't resize the graphic to take all space available/needed into the Widget.
Front end code:
from PyQt5 import QtCore, QtGui, QtWidgets
class Ui_MainWindow(object):
def setupUi(self, MainWindow):
MainWindow.setObjectName("MainWindow")
MainWindow.resize(595, 393)
self.centralwidget = QtWidgets.QWidget(MainWindow)
self.centralwidget.setObjectName("centralwidget")
self.gridLayout = QtWidgets.QGridLayout(self.centralwidget)
self.gridLayout.setObjectName("gridLayout")
self.pushButton = QtWidgets.QPushButton(self.centralwidget)
self.pushButton.setMaximumSize(QtCore.QSize(100, 16777215))
self.pushButton.setObjectName("pushButton")
self.gridLayout.addWidget(self.pushButton, 0, 0, 1, 1)
self.widget = QtWidgets.QWidget(self.centralwidget)
self.widget.setMinimumSize(QtCore.QSize(0, 200))
self.widget.setStyleSheet("background-color: rgb(255, 255, 255);")
self.widget.setObjectName("widget")
self.gridLayout.addWidget(self.widget, 0, 1, 1, 1)
MainWindow.setCentralWidget(self.centralwidget)
self.menubar = QtWidgets.QMenuBar(MainWindow)
self.menubar.setGeometry(QtCore.QRect(0, 0, 595, 21))
self.menubar.setObjectName("menubar")
MainWindow.setMenuBar(self.menubar)
self.statusbar = QtWidgets.QStatusBar(MainWindow)
self.statusbar.setObjectName("statusbar")
MainWindow.setStatusBar(self.statusbar)
self.retranslateUi(MainWindow)
QtCore.QMetaObject.connectSlotsByName(MainWindow)
def retranslateUi(self, MainWindow):
_translate = QtCore.QCoreApplication.translate
MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow"))
self.pushButton.setText(_translate("MainWindow", "PushButton"))
if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
MainWindow = QtWidgets.QMainWindow()
ui = Ui_MainWindow()
ui.setupUi(MainWindow)
MainWindow.show()
sys.exit(app.exec_())
Back end code:
import sys
from PyQt5 import QtCore, QtGui, QtWidgets
from PyQt5.QtWidgets import QMainWindow, QApplication, QWidget, QSizePolicy
from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg as FigureCanvas
from matplotlib.backends.backend_qt5agg import NavigationToolbar2QT as NavigationToolbar
from matplotlib.figure import Figure
from front_end import Ui_MainWindow
class Graph_init(FigureCanvas):
def __init__(self, parent=None):
fig = Figure()
self.axes = fig.add_subplot(111)
self.compute_initial_figure()
FigureCanvas.__init__(self, fig)
self.setParent(parent)
FigureCanvas.setSizePolicy(self, QSizePolicy.Expanding, QSizePolicy.Expanding)
FigureCanvas.updateGeometry(self)
class Graph_populate(Graph_init):
def compute_initial_figure(self):
x = [2000,2001,2002,2003,2004]
y = [10,20,30,40,50]
self.axes.plot(x, y)
class GUI(QMainWindow, Ui_MainWindow):
def __init__(self, parent=None):
super(GUI, self).__init__(parent)
self.setupUi(self)
self.sc = Graph_populate(self.widget)
if __name__ == '__main__':
app = QApplication(sys.argv)
prog = GUI()
prog.showMaximized()
sys.exit(app.exec_())
Thank you
In PyQt you would normally add a widget to your application by adding it to a Layout. In the code you seem to have forgotten to do that step.
So if self.gridLayout is the layout you want your FigureCanvas to reside in, you would need to add the latter to the former as
self.gridLayout.addWidget(self.sc, 0, 1, 1, 1)
The role of self.widget on the other hand is not really clear here and you may probably remove it. The self.centralwidget can take the role of the parent, if it is really needed,
self.sc = Graph_populate(self.centralwidget)
I converted ui file from Pyqt5 designer:
Testing1.py
from PyQt5 import QtCore, QtGui, QtWidgets
class Ui_MainWindow(object):
def setupUi(self, MainWindow):
MainWindow.setObjectName("MainWindow")
MainWindow.resize(800, 600)
self.centralwidget = QtWidgets.QWidget(MainWindow)
self.centralwidget.setObjectName("centralwidget")
self.pushButton = QtWidgets.QPushButton(self.centralwidget)
self.pushButton.setGeometry(QtCore.QRect(380, 180, 112, 34))
self.pushButton.setObjectName("pushButton")
MainWindow.setCentralWidget(self.centralwidget)
self.menubar = QtWidgets.QMenuBar(MainWindow)
self.menubar.setGeometry(QtCore.QRect(0, 0, 800, 31))
self.menubar.setObjectName("menubar")
MainWindow.setMenuBar(self.menubar)
self.statusbar = QtWidgets.QStatusBar(MainWindow)
self.statusbar.setObjectName("statusbar")
MainWindow.setStatusBar(self.statusbar)
self.retranslateUi(MainWindow)
QtCore.QMetaObject.connectSlotsByName(MainWindow)
def retranslateUi(self, MainWindow):
_translate = QtCore.QCoreApplication.translate
MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow"))
self.pushButton.setText(_translate("MainWindow", "PushButton"))
if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
MainWindow = QtWidgets.QMainWindow()
ui = Ui_MainWindow()
ui.setupUi(MainWindow)
MainWindow.show()
sys.exit(app.exec_())
Test1.py < is meant to add methods etc. etc.
import sys
from PyQt5 import QtWidgets, QtCore, QtGui
from testing1 import Ui_MainWindow
class myprog(Ui_MainWindow):
def __init__ (self, dialog):
Ui_MainWindow.__init__(self)
self.setupUi(dialog)
if __name__ == '__main__':
app = QtWidgets.QApplication(sys.argv)
dialog = QtWidgets.QDialog()
test1 = myprog(dialog)
dialog.show()
sys.exit(app.exec_())
If I run Testin1.py it's all ok, but if run second script, test1.py, i get following message:
> builtins.AttributeError: 'QDialog' object has no attribute
> 'setCentralWidget'
I am really confused what to do, I would really really appreciate, if you could help me solve this problem. Any help is more than welcome.
In Testing1.py file, you create a MainWindow.
So in your Test1.py file, you should change the code
dialog = QtWidgets.QDialog()
to
dialog = QtWidgets.QMainWindow()