I am trying to build simple FTP client in Python and for GUI I use PyQt5. Problem is when I run program QTreeView do not showing directories, it is just blank surface. How can I code this to show folders and how to link with this listView below? I was looked on Google but I can not resolve this.
This window I get
And I want something like this
Code:
from PyQt5 import QtCore, QtGui, QtWidgets
class Ui_MainWindow(object):
def setupUi(self, MainWindow):
MainWindow.setObjectName("MainWindow")
MainWindow.resize(852, 637)
MainWindow.setAnimated(True)
MainWindow.setDocumentMode(False)
self.centralwidget = QtWidgets.QWidget(MainWindow)
self.centralwidget.setObjectName("centralwidget")
self.connectButton = QtWidgets.QPushButton(self.centralwidget)
self.connectButton.setGeometry(QtCore.QRect(710, 20, 111, 21))
self.connectButton.setObjectName("connectButton")
self.usernameEdit = QtWidgets.QLineEdit(self.centralwidget)
self.usernameEdit.setGeometry(QtCore.QRect(180, 20, 161, 20))
self.usernameEdit.setObjectName("usernameEdit")
self.passEdit = QtWidgets.QLineEdit(self.centralwidget)
self.passEdit.setGeometry(QtCore.QRect(350, 20, 161, 20))
self.passEdit.setObjectName("passEdit")
self.portEdit = QtWidgets.QLineEdit(self.centralwidget)
self.portEdit.setGeometry(QtCore.QRect(520, 20, 161, 20))
self.portEdit.setReadOnly(False)
self.portEdit.setObjectName("portEdit")
self.hostEdit = QtWidgets.QLineEdit(self.centralwidget)
self.hostEdit.setGeometry(QtCore.QRect(10, 20, 161, 20))
self.hostEdit.setText("")
self.hostEdit.setObjectName("hostEdit")
self.treeView = QtWidgets.QTreeView(self.centralwidget)
self.treeView.setGeometry(QtCore.QRect(10, 60, 401, 281))
self.treeView.setObjectName("treeView")
self.treeView_2 = QtWidgets.QTreeView(self.centralwidget)
self.treeView_2.setGeometry(QtCore.QRect(420, 60, 401, 281))
self.treeView_2.setObjectName("treeView_2")
self.listView = QtWidgets.QListView(self.centralwidget)
self.listView.setGeometry(QtCore.QRect(10, 350, 401, 192))
self.listView.setObjectName("listView")
self.listView_2 = QtWidgets.QListView(self.centralwidget)
self.listView_2.setEnabled(True)
self.listView_2.setGeometry(QtCore.QRect(420, 350, 401, 192))
self.listView_2.setObjectName("listView_2")
self.uploadButton = QtWidgets.QPushButton(self.centralwidget)
self.uploadButton.setGeometry(QtCore.QRect(10, 550, 401, 41))
self.uploadButton.setObjectName("uploadButton")
self.downloadButton = QtWidgets.QPushButton(self.centralwidget)
self.downloadButton.setGeometry(QtCore.QRect(420, 550, 401, 41))
self.downloadButton.setObjectName("downloadButton")
MainWindow.setCentralWidget(self.centralwidget)
self.menubar = QtWidgets.QMenuBar(MainWindow)
self.menubar.setGeometry(QtCore.QRect(0, 0, 852, 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", "My FTP Client"))
self.connectButton.setText(_translate("MainWindow", "Quickconnect"))
self.usernameEdit.setPlaceholderText(_translate("MainWindow", "Username"))
self.passEdit.setPlaceholderText(_translate("MainWindow", "Password"))
self.portEdit.setPlaceholderText(_translate("MainWindow", "Port"))
self.hostEdit.setPlaceholderText(_translate("MainWindow", "Host"))
self.uploadButton.setText(_translate("MainWindow", "Upload"))
self.downloadButton.setText(_translate("MainWindow", "Download"))
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_())
How do you want the QTreeView to show something if it does not tell you what to show?, a QTreeView what it does is show the content of some model, in your case you should use a QFileSystemModel.
from PyQt5 import QtCore, QtGui, QtWidgets
class Ui_MainWindow(object):
...
class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow):
def __init__(self, parent=None):
super(MainWindow, self).__init__(parent)
self.setupUi(self)
model = QtWidgets.QFileSystemModel(self)
model.setRootPath(QtCore.QDir.rootPath())
self.treeView.setModel(model)
self.treeView.expandAll()
self.treeView.setRootIndex(model.index(QtCore.QDir.rootPath()))
if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
w = MainWindow()
w.show()
sys.exit(app.exec_())
Related
I'm having this problem and I have no ideea why is not working.
I'm pretty new to python so I will appreciate if you can help me
It's a very simple GUI, first page open another page when clicking on a button and on a second page I need to open a browse window and take the path as string
Thats the Main Page
from PyQt5 import QtCore, QtGui, QtWidgets
from testGui import Ui_Test
class Ui_PragrammingGUI(object):
def open_test_window(self):
self.window = QtWidgets.QMainWindow()
self.ui = Ui_Test()
self.ui.setupUi(self.window)
self.ui.get_all_serials()
self.window.show()
def setupUi(self, PragrammingGUI):
PragrammingGUI.setObjectName("PragrammingGUI")
PragrammingGUI.resize(237, 177)
self.centralwidget = QtWidgets.QWidget(PragrammingGUI)
self.centralwidget.setObjectName("centralwidget")
self.test_2 = QtWidgets.QPushButton(self.centralwidget)
self.test_2.setGeometry(QtCore.QRect(60, 100, 121, 31))
self.test_2.setObjectName("test_2")
self.test_2.clicked.connect(self.open_test_window)
PragrammingGUI.setCentralWidget(self.centralwidget)
self.menubar = QtWidgets.QMenuBar(PragrammingGUI)
self.menubar.setGeometry(QtCore.QRect(0, 0, 237, 20))
self.menubar.setObjectName("menubar")
PragrammingGUI.setMenuBar(self.menubar)
self.statusbar = QtWidgets.QStatusBar(PragrammingGUI)
self.statusbar.setObjectName("statusbar")
PragrammingGUI.setStatusBar(self.statusbar)
self.retranslateUi(PragrammingGUI)
QtCore.QMetaObject.connectSlotsByName(PragrammingGUI)
def retranslateUi(self, PragrammingGUI):
_translate = QtCore.QCoreApplication.translate
PragrammingGUI.setWindowTitle(_translate("PragrammingGUI", "Programming"))
self.test_2.setText(_translate("PragrammingGUI", "TEST"))
if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
PragrammingGUI = QtWidgets.QMainWindow()
ui = Ui_PragrammingGUI()
ui.setupUi(PragrammingGUI)
PragrammingGUI.show()
sys.exit(app.exec_())
and the one which have browse in it is (ignore the get_all_serials method):
import sys
import os
from cameraID import CameraID
from PyQt5.QtWidgets import QFileDialog, QDialog
from PyQt5 import QtCore, QtGui, QtWidgets
class Ui_Test(QDialog):
def browse_file_src(self):
print('in the function')
file_name = QFileDialog.getOpenFileName(self, 'Open file', '/home/qauser/')
self.lineEdit.setText(file_name[0])
def get_all_serials(self):
self.serial = CameraID()
self.serial.getAllSerial()
return_list = self.serial.getAllSerial()
if len(return_list) > 0:
for i in return_list:
self.comboBox.addItem(i)
else:
self.comboBox.addItem("None")
def setupUi(self, Test):
Test.setObjectName("Test")
Test.resize(397, 108)
self.centralwidget = QtWidgets.QWidget(Test)
self.centralwidget.setObjectName("centralwidget")
self.lineEdit = QtWidgets.QLineEdit(self.centralwidget)
self.lineEdit.setGeometry(QtCore.QRect(10, 10, 291, 21))
self.lineEdit.setObjectName("lineEdit")
self.lineEdit.setPlaceholderText("Chose file")
self.browseBtn = QtWidgets.QPushButton(self.centralwidget)#, clicked=lambda: self.browseBtn)
self.browseBtn.setGeometry(QtCore.QRect(310, 10, 80, 23))
self.browseBtn.setObjectName("browseBtn")
self.browseBtn.clicked.connect(self.browseBtn)
self.radioButton = QtWidgets.QRadioButton(self.centralwidget)
self.radioButton.setGeometry(QtCore.QRect(10, 40, 51, 21))
self.radioButton.setObjectName("radioButton")
self.radioButton_2 = QtWidgets.QRadioButton(self.centralwidget)
self.radioButton_2.setGeometry(QtCore.QRect(60, 40, 71, 21))
self.radioButton_2.setObjectName("radioButton_2")
self.pushButton = QtWidgets.QPushButton(self.centralwidget)
self.pushButton.setGeometry(QtCore.QRect(310, 40, 80, 23))
self.pushButton.setObjectName("pushButton")
self.comboBox = QtWidgets.QComboBox(self.centralwidget)
self.comboBox.setGeometry(QtCore.QRect(120, 40, 181, 23))
self.comboBox.setObjectName("comboBox")
Test.setCentralWidget(self.centralwidget)
self.menubar = QtWidgets.QMenuBar(Test)
self.menubar.setGeometry(QtCore.QRect(0, 0, 397, 20))
self.menubar.setObjectName("menubar")
Test.setMenuBar(self.menubar)
self.statusbar = QtWidgets.QStatusBar(Test)
self.statusbar.setObjectName("statusbar")
Test.setStatusBar(self.statusbar)
self.retranslateUi(Test)
QtCore.QMetaObject.connectSlotsByName(Test)
def retranslateUi(self, Test):
_translate = QtCore.QCoreApplication.translate
Test.setWindowTitle(_translate("Test", "MainWindow"))
self.browseBtn.setText(_translate("Test", "Browse"))
self.radioButton.setText(_translate("Test", "Ok"))
self.radioButton_2.setText(_translate("Test", "Failed"))
self.pushButton.setText(_translate("Test", "Start"))
if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
Test = QtWidgets.QMainWindow()
ui = Ui_Test()
ui.setupUi(Test)
Test.show()
sys.exit(app.exec_())
I think the issue is this: self.browseBtn.clicked.connect(self.browseBtn).
You are trying to connect the click event to the button itself.
You probably want to do something like: self.browseBtn.clicked.connect(self.method_to_call_when_clicked) where method_to_call_when_clicked is replaced by the name of the method you wish to call when it is clicked.
An example already in your code is:
self.test_2.clicked.connect(self.open_test_window)
I have two windows, first window is 'FirstWindow' and second is 'Calendar'. first window has one push button (pbSelectDate) and one label (lbDate). calendar window has calendar (CalendarBox) and one push button (pbSelect).
when i click select (pbSelectDate) from first window, calendar window pops up. I select the date and press select button (pbSelect) in the calendar window. i want to print the selected date to the label (lbDate) in the first window.
thanks in advance. :)
this is the first window script.
from PyQt5 import QtCore, QtGui, QtWidgets
from Calendar import Ui_CalendarWindow
class Ui_FirstWindow(object):
def Open_Calendar(self):
self.window = QtWidgets.QMainWindow()
self.ui = Ui_CalendarWindow()
self.ui.setupUi(self.window)
self.window.show()
def setupUi(self, FirstWindow):
FirstWindow.setObjectName("FirstWindow")
FirstWindow.resize(654, 242)
self.centralwidget = QtWidgets.QWidget(FirstWindow)
self.centralwidget.setObjectName("centralwidget")
self.lbDate = QtWidgets.QLabel(self.centralwidget)
self.lbDate.setGeometry(QtCore.QRect(330, 70, 281, 131))
font = QtGui.QFont()
font.setPointSize(16)
font.setBold(True)
font.setWeight(75)
self.lbDate.setFont(font)
self.lbDate.setLayoutDirection(QtCore.Qt.LeftToRight)
self.lbDate.setObjectName("lbDate")
self.pbSelectDate = QtWidgets.QPushButton(self.centralwidget)
self.pbSelectDate.setGeometry(QtCore.QRect(80, 100, 191, 61))
self.pbSelectDate.setObjectName("pbSelectDate")
self.pbSelectDate.clicked.connect(self.Open_Calendar)
FirstWindow.setCentralWidget(self.centralwidget)
self.statusbar = QtWidgets.QStatusBar(FirstWindow)
self.statusbar.setObjectName("statusbar")
FirstWindow.setStatusBar(self.statusbar)
self.retranslateUi(FirstWindow)
QtCore.QMetaObject.connectSlotsByName(FirstWindow)
def retranslateUi(self, FirstWindow):
_translate = QtCore.QCoreApplication.translate
FirstWindow.setWindowTitle(_translate("FirstWindow", "MainWindow"))
self.lbDate.setText(_translate("FirstWindow", "Sep"))
self.pbSelectDate.setText(_translate("FirstWindow", "Select Date"))
if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
FirstWindow = QtWidgets.QMainWindow()
ui = Ui_FirstWindow()
ui.setupUi(FirstWindow)
FirstWindow.show()
sys.exit(app.exec_())
this is the Calendar window script..
from PyQt5 import QtCore, QtGui, QtWidgets
class Ui_CalendarWindow(object):
def PickedDate(self,var):
self.selecteddate = self.CalendarBox.selectedDate()
#print(self.selecteddate.toString('MMM')+'-'+self.selecteddate.toString('yyyy'))
def setupUi(self, CalendarWindow):
CalendarWindow.setObjectName("CalendarWindow")
CalendarWindow.resize(512, 458)
self.centralwidget = QtWidgets.QWidget(CalendarWindow)
self.centralwidget.setObjectName("centralwidget")
self.CalendarBox = QtWidgets.QCalendarWidget(self.centralwidget)
self.CalendarBox.setGeometry(QtCore.QRect(20, 20, 464, 289))
self.CalendarBox.setObjectName("CalendarBox")
self.pbSelect = QtWidgets.QPushButton(self.centralwidget)
self.pbSelect.setGeometry(QtCore.QRect(160, 330, 181, 60))
font = QtGui.QFont()
font.setPointSize(10)
font.setBold(True)
font.setWeight(75)
self.pbSelect.setFont(font)
self.pbSelect.setObjectName("pbSelect")
self.pbSelect.clicked.connect(self.PickedDate)
CalendarWindow.setCentralWidget(self.centralwidget)
self.statusbar = QtWidgets.QStatusBar(CalendarWindow)
self.statusbar.setObjectName("statusbar")
CalendarWindow.setStatusBar(self.statusbar)
self.retranslateUi(CalendarWindow)
QtCore.QMetaObject.connectSlotsByName(CalendarWindow)
def retranslateUi(self, CalendarWindow):
_translate = QtCore.QCoreApplication.translate
CalendarWindow.setWindowTitle(_translate("CalendarWindow", "MainWindow"))
self.pbSelect.setText(_translate("CalendarWindow", "Select"))
if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
CalendarWindow = QtWidgets.QMainWindow()
ui = Ui_CalendarWindow()
ui.setupUi(CalendarWindow)
CalendarWindow.show()
sys.exit(app.exec_())
Do not modify the code generated by Qt Designer but create another class that inherits from the appropriate widget and use the initial class to fill it.
QLabel.setText(const QString )
Setting the text clears any previous content.
from PyQt5 import QtCore, QtGui, QtWidgets
#from Calendar import Ui_CalendarWindow
class Ui_CalendarWindow(object):
def setupUi(self, CalendarWindow):
CalendarWindow.setObjectName("CalendarWindow")
CalendarWindow.resize(512, 458)
self.centralwidget = QtWidgets.QWidget(CalendarWindow)
self.centralwidget.setObjectName("centralwidget")
self.CalendarBox = QtWidgets.QCalendarWidget(self.centralwidget)
self.CalendarBox.setGeometry(QtCore.QRect(20, 20, 464, 289))
self.CalendarBox.setObjectName("CalendarBox")
self.pbSelect = QtWidgets.QPushButton(self.centralwidget)
self.pbSelect.setGeometry(QtCore.QRect(160, 330, 181, 60))
font = QtGui.QFont()
font.setPointSize(10)
font.setBold(True)
font.setWeight(75)
self.pbSelect.setFont(font)
self.pbSelect.setObjectName("pbSelect")
# self.pbSelect.clicked.connect(self.PickedDate)
CalendarWindow.setCentralWidget(self.centralwidget)
self.statusbar = QtWidgets.QStatusBar(CalendarWindow)
self.statusbar.setObjectName("statusbar")
CalendarWindow.setStatusBar(self.statusbar)
self.retranslateUi(CalendarWindow)
QtCore.QMetaObject.connectSlotsByName(CalendarWindow)
def retranslateUi(self, CalendarWindow):
_translate = QtCore.QCoreApplication.translate
CalendarWindow.setWindowTitle(_translate("CalendarWindow", "MainWindow"))
self.pbSelect.setText(_translate("CalendarWindow", "Select"))
class Ui_FirstWindow(object):
def setupUi(self, FirstWindow):
FirstWindow.setObjectName("FirstWindow")
FirstWindow.resize(654, 242)
self.centralwidget = QtWidgets.QWidget(FirstWindow)
self.centralwidget.setObjectName("centralwidget")
self.lbDate = QtWidgets.QLabel(self.centralwidget)
self.lbDate.setGeometry(QtCore.QRect(330, 70, 281, 131))
font = QtGui.QFont()
font.setPointSize(16)
font.setBold(True)
font.setWeight(75)
self.lbDate.setFont(font)
self.lbDate.setLayoutDirection(QtCore.Qt.LeftToRight)
self.lbDate.setObjectName("lbDate")
self.pbSelectDate = QtWidgets.QPushButton(self.centralwidget)
self.pbSelectDate.setGeometry(QtCore.QRect(80, 100, 191, 61))
self.pbSelectDate.setObjectName("pbSelectDate")
# self.pbSelectDate.clicked.connect(self.Open_Calendar)
FirstWindow.setCentralWidget(self.centralwidget)
self.statusbar = QtWidgets.QStatusBar(FirstWindow)
self.statusbar.setObjectName("statusbar")
FirstWindow.setStatusBar(self.statusbar)
self.retranslateUi(FirstWindow)
QtCore.QMetaObject.connectSlotsByName(FirstWindow)
def retranslateUi(self, FirstWindow):
_translate = QtCore.QCoreApplication.translate
FirstWindow.setWindowTitle(_translate("FirstWindow", "MainWindow"))
self.lbDate.setText(_translate("FirstWindow", "Sep"))
self.pbSelectDate.setText(_translate("FirstWindow", "Select Date"))
class CalendarWindow(QtWidgets.QMainWindow, Ui_CalendarWindow): # +
def __init__(self):
super(CalendarWindow, self).__init__()
self.setupUi(self)
class FirstWindow(QtWidgets.QMainWindow, Ui_FirstWindow): # +
def __init__(self):
super(FirstWindow, self).__init__()
self.setupUi(self)
self.pbSelectDate.clicked.connect(self.Open_Calendar)
def Open_Calendar(self):
self.window = CalendarWindow()
self.window.setupUi(self.window)
self.window.show()
self.window.pbSelect.clicked.connect(self.PickedDate)
def PickedDate(self): # , var
self.selecteddate = self.window.CalendarBox.selectedDate()
# print(self.selecteddate.toString('MMM')+'-'+self.selecteddate.toString('yyyy'))
self.lbDate.setText(self.selecteddate.toString('ddd-MMM-yyyy')) # <---
if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
w = FirstWindow()
w.show()
sys.exit(app.exec_())
I am writing GUI app with the help of Qt Designer. The app consists of multiple windows, so when the user clicks the push button on one window, the next window should open and the current window should hide. I achieved this feature for going from window 1 to window 2. But I am not able to do this to move from window 2 to window 3. I think this might be because the window 2 gets user arguments.
Is there any way to hide the window which gets user arguments?
The code is as follows:
Class for main window:
import sys
from PyQt5 import QtCore, QtGui, QtWidgets
import user_data
class MainWindow(object):
def user_data(self):
self.user_data_window = QtWidgets.QMainWindow()
self.next_window = user_data.Ui_UserData()
self.next_window.setupUi(self.user_data_window)
main_window.hide()
self.user_data_window.show()
def setupUi(self, MainWindow):
MainWindow.setObjectName("MainWindow")
MainWindow.resize(640, 480)
self.centralwidget = QtWidgets.QWidget(MainWindow)
self.centralwidget.setObjectName("centralwidget")
self.label = QtWidgets.QLabel(self.centralwidget)
self.label.setGeometry(QtCore.QRect(140, 100, 361, 81))
font = QtGui.QFont()
font.setPointSize(24)
font.setBold(True)
font.setWeight(75)
self.label.setFont(font)
self.label.setObjectName("label")
self.pushButton = QtWidgets.QPushButton(self.centralwidget)
self.pushButton.setGeometry(QtCore.QRect(260, 260, 75, 51))
self.pushButton.setObjectName("pushButton")
self.pushButton.clicked.connect(self.user_data)
MainWindow.setCentralWidget(self.centralwidget)
self.menubar = QtWidgets.QMenuBar(MainWindow)
self.menubar.setGeometry(QtCore.QRect(0, 0, 640, 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", "Main Window"))
self.label.setText(_translate("MainWindow", " Manager"))
self.pushButton.setText(_translate("MainWindow", "Lets Start!"))
if __name__ == "__main__":
app = QtWidgets.QApplication(sys.argv)
main_window = QtWidgets.QMainWindow()
ui = MainWindow()
ui.setupUi(main_window)
main_window.show()
sys.exit(app.exec_())
user_data.py ---> window 2
from PyQt5 import QtCore, QtGui, QtWidgets
import start_recording
class Ui_UserData(object):
def start_record(self):
self.window = QtWidgets.QMainWindow()
self.ui = start_recording.Ui_StartRecording()
self.ui.setupUi(self.window)
"""
This is the part not working
"""
MainWindow.hide()
self.window.show()
def setupUi(self, MainWindow):
MainWindow.setObjectName("MainWindow")
MainWindow.resize(640, 480)
self.centralwidget = QtWidgets.QWidget(MainWindow)
self.centralwidget.setObjectName("centralwidget")
self.groupBox_speaker_data = QtWidgets.QGroupBox(self.centralwidget)
self.groupBox_speaker_data.setGeometry(QtCore.QRect(80, 30, 481, 381))
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Preferred, QtWidgets.QSizePolicy.Preferred)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(84)
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Preferred, QtWidgets.QSizePolicy.Preferred)
self.groupBox_speaker_data.setSizePolicy(sizePolicy)
font = QtGui.QFont()
font.setBold(True)
font.setWeight(75)
self.groupBox_speaker_data.setFont(font)
self.groupBox_speaker_data.setObjectName("groupBox_speaker_data")
self.label_name = QtWidgets.QLabel(self.groupBox_speaker_data)
self.label_name.setGeometry(QtCore.QRect(30, 60, 47, 13))
self.label_name.setObjectName("label_name")
self.label_age = QtWidgets.QLabel(self.groupBox_speaker_data)
self.label_age.setGeometry(QtCore.QRect(30, 120, 47, 13))
self.label_age.setObjectName("label_age")
self.label_id = QtWidgets.QLabel(self.groupBox_speaker_data)
self.label_id.setGeometry(QtCore.QRect(30, 90, 47, 13))
self.label_id.setObjectName("label_id")
self.label_gender = QtWidgets.QLabel(self.groupBox_speaker_data)
self.label_gender.setGeometry(QtCore.QRect(30, 150, 47, 13))
self.label_gender.setObjectName("label_gender")
self.lineEdit_name = QtWidgets.QLineEdit(self.groupBox_speaker_data)
self.lineEdit_name.setGeometry(QtCore.QRect(110, 60, 141, 20))
self.lineEdit_name.setObjectName("lineEdit_name")
self.lineEdit_id = QtWidgets.QLineEdit(self.groupBox_speaker_data)
self.lineEdit_id.setGeometry(QtCore.QRect(110, 90, 141, 20))
self.lineEdit_id.setObjectName("lineEdit_id")
self.spinBox_age = QtWidgets.QSpinBox(self.groupBox_speaker_data)
self.spinBox_age.setGeometry(QtCore.QRect(110, 120, 42, 22))
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Minimum)
sizePolicy.setHorizontalStretch(18)
sizePolicy.setVerticalStretch(78)
self.spinBox_age.setSizePolicy(sizePolicy)
self.spinBox_age.setMinimum(18)
self.spinBox_age.setObjectName("spinBox_age")
self.comboBox_gender = QtWidgets.QComboBox(self.groupBox_speaker_data)
self.comboBox_gender.setGeometry(QtCore.QRect(110, 150, 69, 22))
self.comboBox_gender.setObjectName("comboBox_gender")
self.comboBox_gender.addItem("")
self.comboBox_gender.addItem("")
self.comboBox_gender.addItem("")
self.pushButton = QtWidgets.QPushButton(self.groupBox_speaker_data)
self.pushButton.setGeometry(QtCore.QRect(370, 330, 75, 23))
self.pushButton.setObjectName("pushButton")
self.pushButton.clicked.connect(self.start_record)
MainWindow.setCentralWidget(self.centralwidget)
self.menubar = QtWidgets.QMenuBar(MainWindow)
self.menubar.setGeometry(QtCore.QRect(0, 0, 640, 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", "User Data"))
self.groupBox_speaker_data.setTitle(_translate("MainWindow", "Speaker Data"))
self.label_name.setText(_translate("MainWindow", "Name:"))
self.label_age.setText(_translate("MainWindow", "Age:"))
self.label_id.setText(_translate("MainWindow", "ID:"))
self.label_gender.setText(_translate("MainWindow", "Gender:"))
self.comboBox_gender.setItemText(0, _translate("MainWindow", "Male"))
self.comboBox_gender.setItemText(1, _translate("MainWindow", "Female"))
self.comboBox_gender.setItemText(2, _translate("MainWindow", "Unknown"))
self.pushButton.setText(_translate("MainWindow", "NEXT"))
if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
MainWindow = QtWidgets.QMainWindow()
ui = Ui_UserData()
ui.setupUi(MainWindow)
MainWindow.show()
sys.exit(app.exec_())
start_recording.py ----> window 3
from PyQt5 import QtCore, QtGui, QtWidgets
class Ui_StartRecording(object):
def setupUi(self, MainWindow):
MainWindow.setObjectName("MainWindow")
MainWindow.resize(640, 480)
self.centralwidget = QtWidgets.QWidget(MainWindow)
self.centralwidget.setObjectName("centralwidget")
self.label = QtWidgets.QLabel(self.centralwidget)
self.label.setGeometry(QtCore.QRect(160, 120, 331, 91))
font = QtGui.QFont()
font.setFamily("Arial Black")
font.setPointSize(18)
font.setBold(True)
font.setWeight(75)
self.label.setFont(font)
self.label.setObjectName("label")
self.label_2 = QtWidgets.QLabel(self.centralwidget)
self.label_2.setGeometry(QtCore.QRect(260, 200, 101, 51))
font = QtGui.QFont()
font.setPointSize(14)
font.setBold(True)
font.setWeight(75)
self.label_2.setFont(font)
self.label_2.setObjectName("label_2")
self.pushButton = QtWidgets.QPushButton(self.centralwidget)
self.pushButton.setGeometry(QtCore.QRect(260, 260, 75, 23))
self.pushButton.setObjectName("pushButton")
MainWindow.setCentralWidget(self.centralwidget)
self.menubar = QtWidgets.QMenuBar(MainWindow)
self.menubar.setGeometry(QtCore.QRect(0, 0, 640, 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.label.setText(_translate("MainWindow", "Lets begin"))
self.label_2.setText(_translate("MainWindow", "xxx!"))
self.pushButton.setText(_translate("MainWindow", "PushButton"))
if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
MainWindow = QtWidgets.QMainWindow()
ui = Ui_StartRecording()
ui.setupUi(MainWindow)
MainWindow.show()
sys.exit(app.exec_())
class Ui_UserData(object):
def start_record(self):
self.window = QtWidgets.QMainWindow()
self.ui = start_recording.Ui_StartRecording()
self.ui.setupUi(self.window)
"""
This is the part not working
"""
MainWindow.hide()
^^^^^^^^ ---- there is no 'MainWindow' variable available to class, hence it doesn't know what to hide here.
Solution is:
class Ui_UserData(object):
def start_record(self):
self.window = QtWidgets.QMainWindow()
self.ui = start_recording.Ui_StartRecording()
self.ui.setupUi(self.window)
"""
This part is now working!
"""
self.mw.hide()
self.window.show()
def setupUi(self, MainWindow):
self.mw = MainWindow
# ^^^^^^^^ - You create class variable for mainwindow object
I have some code for a very generic/blank GUI with some labels and pushbuttons and an LCD widget. I also have some code for a separate window which just uses an LCD widget to display the time. My question is how do I insert to code for the clock into the generic GUI code to make that LCD widget display the time?
from PyQt5.QtCore import QTime, QTimer
from PyQt5.QtWidgets import QApplication, QLCDNumber
class DigitalClock(QLCDNumber):
def __init__(self, parent=None):
super(DigitalClock, self).__init__(parent)
self.setSegmentStyle(QLCDNumber.Filled)
timer = QTimer(self)
timer.timeout.connect(self.showTime)
timer.start(1000)
self.showTime()
self.setWindowTitle("Digital Clock")
self.resize(150, 60)
def showTime(self):
time = QTime.currentTime()
text = time.toString('hh:mm')
if (time.second() % 2) == 0:
text = text[:2] + ' ' + text[3:]
self.display(text)
if __name__ == '__main__':
import sys
app = QApplication(sys.argv)
clock = DigitalClock()
clock.show()
sys.exit(app.exec_())
That's the code for the simple clock and I want to insert that into the following to make the LCD widget display the time like this one does:
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.Clock = QtWidgets.QWidget(self.centralwidget)
self.Clock.setGeometry(QtCore.QRect(60, 420, 120, 80))
self.Clock.setObjectName("Clock")
self.DigitalClock = QtWidgets.QLCDNumber(self.centralwidget)
self.DigitalClock.setGeometry(QtCore.QRect(110, 190, 64, 23))
self.DigitalClock.setDigitCount(8)
self.DigitalClock.setObjectName("DigitalClock")
self.pushButton = QtWidgets.QPushButton(self.centralwidget)
self.pushButton.setGeometry(QtCore.QRect(100, 60, 75, 23))
self.pushButton.setObjectName("pushButton")
self.pushButton_2 = QtWidgets.QPushButton(self.centralwidget)
self.pushButton_2.setGeometry(QtCore.QRect(100, 110, 75, 23))
self.pushButton_2.setObjectName("pushButton_2")
self.pushButton_3 = QtWidgets.QPushButton(self.centralwidget)
self.pushButton_3.setGeometry(QtCore.QRect(100, 150, 75, 23))
self.pushButton_3.setObjectName("pushButton_3")
self.pushButton_4 = QtWidgets.QPushButton(self.centralwidget)
self.pushButton_4.setGeometry(QtCore.QRect(230, 60, 75, 23))
self.pushButton_4.setObjectName("pushButton_4")
self.pushButton_5 = QtWidgets.QPushButton(self.centralwidget)
self.pushButton_5.setGeometry(QtCore.QRect(220, 100, 75, 23))
self.pushButton_5.setObjectName("pushButton_5")
self.pushButton_6 = QtWidgets.QPushButton(self.centralwidget)
self.pushButton_6.setGeometry(QtCore.QRect(230, 150, 75, 23))
self.pushButton_6.setObjectName("pushButton_6")
self.label = QtWidgets.QLabel(self.centralwidget)
self.label.setGeometry(QtCore.QRect(20, 60, 47, 13))
self.label.setObjectName("label")
self.label_2 = QtWidgets.QLabel(self.centralwidget)
self.label_2.setGeometry(QtCore.QRect(20, 120, 47, 13))
self.label_2.setObjectName("label_2")
self.label_3 = QtWidgets.QLabel(self.centralwidget)
self.label_3.setGeometry(QtCore.QRect(20, 160, 47, 13))
self.label_3.setObjectName("label_3")
mainWindow.setCentralWidget(self.centralwidget)
self.menubar = QtWidgets.QMenuBar(mainWindow)
self.menubar.setGeometry(QtCore.QRect(0, 0, 800, 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", "Sim Monitor"))
self.pushButton.setText(_translate("mainWindow", "PushButton"))
self.pushButton_2.setText(_translate("mainWindow", "PushButton"))
self.pushButton_3.setText(_translate("mainWindow", "PushButton"))
self.pushButton_4.setText(_translate("mainWindow", "PushButton"))
self.pushButton_5.setText(_translate("mainWindow", "PushButton"))
self.pushButton_6.setText(_translate("mainWindow", "PushButton"))
self.label.setText(_translate("mainWindow", "TextLabel"))
self.label_2.setText(_translate("mainWindow", "TextLabel"))
self.label_3.setText(_translate("mainWindow", "TextLabel"))
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_())
Simple solution:
Assuming that the first file is called DigitalClock.py and the second main.py then it is only necessary to add the import to main.py and change the line that the QLCDNumber creates:
main.py
from DigitalClock import DigitalClock
# ...
self.DigitalClock = DigitalClock(self.centralwidget) # QtWidgets.QLCDNumber(self.centralwidget)
Long solution:
Promote the QLCDNumber to use the DigitalClock, you could take the guide of this other answer where you would exchange QVideoWidget with DigitalClock and PyQt5.QtMultimediaWidgets with DigitalClock.
The other way is to create a widget plugin so that it can be used directly in Qt Designer.
DigitalClockFile.py
from PyQt5.QtCore import QTime, QTimer
from PyQt5.QtWidgets import QApplication, QLCDNumber
class DigitalClock(QLCDNumber):
def __init__(self, parent=None):
super(DigitalClock, self).__init__(parent)
self.setSegmentStyle(QLCDNumber.Filled)
self.setDigitCount(10)
timer = QTimer(self)
timer.timeout.connect(self.showTime)
timer.start(1000)
self.showTime()
self.setWindowTitle("Digital Clock")
self.resize(150, 60)
def showTime(self):
time = QTime.currentTime()
text = time.toString('hh:mm:ss')
if (time.second() % 2) == 0:
text = text[:2] + ' ' + text[3:5]+' '+text[6:]
self.display(text)
if __name__ == '__main__':
import sys
app = QApplication(sys.argv)
clock = DigitalClock()
clock.show()
sys.exit(app.exec_())
generatedUI.py (from QtDesigner)
from PyQt5 import QtCore, QtGui, QtWidgets
import sys
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.Clock = QtWidgets.QWidget(self.centralwidget)
self.Clock.setGeometry(QtCore.QRect(60, 420, 120, 80))
self.Clock.setObjectName("Clock")
# Remove DigitalClock FROM YOUR UI DESIGN,Since you already implemented your Digital Clock
# I would suggest regenerating .py from .ui after deleting digitalClock
# instead of commenting uot like me
# self.DigitalClock = QtWidgets.QLCDNumber(self.centralwidget)
# self.DigitalClock.setGeometry(QtCore.QRect(110, 190, 64, 23))
# self.DigitalClock.setDigitCount(8)
# self.DigitalClock.setObjectName("DigitalClock")
self.pushButton = QtWidgets.QPushButton(self.centralwidget)
self.pushButton.setGeometry(QtCore.QRect(100, 60, 75, 23))
self.pushButton.setObjectName("pushButton")
self.pushButton_2 = QtWidgets.QPushButton(self.centralwidget)
self.pushButton_2.setGeometry(QtCore.QRect(100, 110, 75, 23))
self.pushButton_2.setObjectName("pushButton_2")
self.pushButton_3 = QtWidgets.QPushButton(self.centralwidget)
self.pushButton_3.setGeometry(QtCore.QRect(100, 150, 75, 23))
self.pushButton_3.setObjectName("pushButton_3")
self.pushButton_4 = QtWidgets.QPushButton(self.centralwidget)
self.pushButton_4.setGeometry(QtCore.QRect(230, 60, 75, 23))
self.pushButton_4.setObjectName("pushButton_4")
self.pushButton_5 = QtWidgets.QPushButton(self.centralwidget)
self.pushButton_5.setGeometry(QtCore.QRect(220, 100, 75, 23))
self.pushButton_5.setObjectName("pushButton_5")
self.pushButton_6 = QtWidgets.QPushButton(self.centralwidget)
self.pushButton_6.setGeometry(QtCore.QRect(230, 150, 75, 23))
self.pushButton_6.setObjectName("pushButton_6")
self.label = QtWidgets.QLabel(self.centralwidget)
self.label.setGeometry(QtCore.QRect(20, 60, 47, 13))
self.label.setObjectName("label")
self.label_2 = QtWidgets.QLabel(self.centralwidget)
self.label_2.setGeometry(QtCore.QRect(20, 120, 47, 13))
self.label_2.setObjectName("label_2")
self.label_3 = QtWidgets.QLabel(self.centralwidget)
self.label_3.setGeometry(QtCore.QRect(20, 160, 47, 13))
self.label_3.setObjectName("label_3")
mainWindow.setCentralWidget(self.centralwidget)
self.menubar = QtWidgets.QMenuBar(mainWindow)
self.menubar.setGeometry(QtCore.QRect(0, 0, 800, 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", "Sim Monitor"))
self.pushButton.setText(_translate("mainWindow", "PushButton"))
self.pushButton_2.setText(_translate("mainWindow", "PushButton"))
self.pushButton_3.setText(_translate("mainWindow", "PushButton"))
self.pushButton_4.setText(_translate("mainWindow", "PushButton"))
self.pushButton_5.setText(_translate("mainWindow", "PushButton"))
self.pushButton_6.setText(_translate("mainWindow", "PushButton"))
self.label.setText(_translate("mainWindow", "TextLabel"))
self.label_2.setText(_translate("mainWindow", "TextLabel"))
self.label_3.setText(_translate("mainWindow", "TextLabel"))
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_())
main.py
from DigitalClockFile import DigitalClock
from generatedUI import Ui_mainWindow
from PyQt5.QtCore import QTime, QTimer
from PyQt5.QtWidgets import QApplication, QLCDNumber
from PyQt5 import QtWidgets,QtCore
class transformedUI(Ui_mainWindow):
def __init__(self):
super(transformedUI,self).__init__()
def setupUi(self,mainWindow):
super(transformedUI,self).setupUi(mainWindow)
self.DigitalClock=DigitalClock(self.centralwidget)
self.DigitalClock.setGeometry(QtCore.QRect(110, 190, 200, 100))
if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
mainWindow = QtWidgets.QMainWindow()
ui = transformedUI()
ui.setupUi(mainWindow)
mainWindow.show()
sys.exit(app.exec_())
Add all the three files in the single directory.Since you already implement DigitalClock dont add the clock in thi UI just inherit class generated by QtDEsigner and add your clock in the inherited transformedUI.py and simply running the main.py will achieve desired task.Hope it helps
# -*- coding: utf-8 -*-
# Form implementation generated from reading ui file 'mainwindow.ui'
#
# Created by: PyQt5 UI code generator 5.8.2
#
# WARNING! All changes made in this file will be lost!
from PyQt5 import QtCore, QtGui, QtWidgets
class Ui_MainWindow(object):
def setupUi(self, MainWindow):
MainWindow.setObjectName("MainWindow")
MainWindow.resize(733, 497)
self.centralWidget = QtWidgets.QWidget(MainWindow)
self.centralWidget.setObjectName("centralWidget")
self.My_2 = QtWidgets.QPushButton(self.centralWidget)
self.My_2.setGeometry(QtCore.QRect(0, 30, 101, 41))
self.My_2.setStyleSheet("")
self.My_2.setText("")
icon = QtGui.QIcon()
icon.addPixmap(QtGui.QPixmap("../../Major Project/Add a game button 1.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
self.My_2.setIcon(icon)
self.My_2.setIconSize(QtCore.QSize(100, 100))
self.My_2.setObjectName("My_2")
self.My_3 = QtWidgets.QPushButton(self.centralWidget)
self.My_3.setGeometry(QtCore.QRect(0, 80, 101, 41))
self.My_3.setObjectName("My_3")
self.My_3.clicked.connect(self.editbutton) #EDIT BUTTON
self.My_4 = QtWidgets.QPushButton(self.centralWidget)
self.My_4.setGeometry(QtCore.QRect(60, 260, 31, 31))
self.My_4.setText("")
icon1 = QtGui.QIcon()
icon1.addPixmap(QtGui.QPixmap("../../Major Project/settings button.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
self.My_4.setIcon(icon1)
self.My_4.setIconSize(QtCore.QSize(32, 32))
self.My_4.setObjectName("My_4")
self.My_5 = QtWidgets.QPushButton(self.centralWidget)
self.My_5.setGeometry(QtCore.QRect(0, 210, 101, 41))
self.My_5.setObjectName("My_5")
self.line_3 = QtWidgets.QFrame(self.centralWidget)
self.line_3.setGeometry(QtCore.QRect(100, 0, 20, 341))
self.line_3.setFrameShape(QtWidgets.QFrame.VLine)
self.line_3.setFrameShadow(QtWidgets.QFrame.Sunken)
self.line_3.setObjectName("line_3")
self.timeEdit = QtWidgets.QTimeEdit(self.centralWidget)
self.timeEdit.setGeometry(QtCore.QRect(0, 300, 101, 22))
self.timeEdit.setObjectName("timeEdit")
self.scrollArea = QtWidgets.QScrollArea(self.centralWidget)
self.scrollArea.setGeometry(QtCore.QRect(130, 30, 571, 271))
self.scrollArea.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOn)
self.scrollArea.setWidgetResizable(True)
self.scrollArea.setObjectName("scrollArea")
self.scrollAreaWidgetContents = QtWidgets.QWidget()
self.scrollAreaWidgetContents.setGeometry(QtCore.QRect(0, 0, 552, 269))
self.scrollAreaWidgetContents.setObjectName("scrollAreaWidgetContents")
self.graphicsView_2 = QtWidgets.QGraphicsView(self.scrollAreaWidgetContents)
self.graphicsView_2.setGeometry(QtCore.QRect(160, 30, 101, 81))
self.graphicsView_2.setObjectName("graphicsView_2")
self.graphicsView = QtWidgets.QGraphicsView(self.scrollAreaWidgetContents)
self.graphicsView.setGeometry(QtCore.QRect(30, 30, 101, 81))
self.graphicsView.setObjectName("graphicsView")
self.line_2 = QtWidgets.QFrame(self.scrollAreaWidgetContents)
self.line_2.setGeometry(QtCore.QRect(10, 10, 531, 20))
self.line_2.setFrameShape(QtWidgets.QFrame.HLine)
self.line_2.setFrameShadow(QtWidgets.QFrame.Sunken)
self.line_2.setObjectName("line_2")
self.pushButton = QtWidgets.QPushButton(self.scrollAreaWidgetContents)
self.pushButton.setGeometry(QtCore.QRect(40, 110, 81, 23))
self.pushButton.setObjectName("pushButton")
self.pushButton_2 = QtWidgets.QPushButton(self.scrollAreaWidgetContents)
self.pushButton_2.setGeometry(QtCore.QRect(170, 110, 81, 23))
self.pushButton_2.setObjectName("pushButton_2")
self.scrollArea.setWidget(self.scrollAreaWidgetContents)
MainWindow.setCentralWidget(self.centralWidget)
self.menuBar = QtWidgets.QMenuBar(MainWindow)
self.menuBar.setGeometry(QtCore.QRect(0, 0, 733, 21))
self.menuBar.setObjectName("menuBar")
MainWindow.setMenuBar(self.menuBar)
self.mainToolBar = QtWidgets.QToolBar(MainWindow)
self.mainToolBar.setObjectName("mainToolBar")
MainWindow.addToolBar(QtCore.Qt.TopToolBarArea, self.mainToolBar)
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.My_3.setText(_translate("MainWindow", "Edit"))
self.My_5.setText(_translate("MainWindow", "Help"))
self.pushButton.setText(_translate("MainWindow", "PushButton"))
self.pushButton_2.setText(_translate("MainWindow", "PushButton"))
def editbutton(self):
if __name__ == "__main__":
import sys, editui
app = QtWidgets.QApplication(sys.argv)
MainWindow = QtWidgets.QMainWindow()
ui = editui.Ui_MainWindow()
ui.setupUi(MainWindow)
MainWindow.show()
sys.exit(app.exec_())
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_())
I need help with this: the window keeps exiting when My_3 button is pressed, after both windows opening for a split second. editui.py is a generic auto-generated file with PyQt, so there's that.
If anyone can help me out, thanks!