Answers for "pyqt dialog"

0

pyqt5 message box

# in pyqt5 it needs to be PyQt5.QtWidgets
msg=QMessageBox() # create an instance of it
msg.setIcon(QMessageBox.Information) # set icon
msg.setText("This is a message box") # set text
msg.setInformativeText("This is additional information") # set information under the main text
msg.setWindowTitle("MessageBox demo") # set title
msg.setDetailedText("The details are as follows:") # a button for more details will add in
msg.setStandardButtons(QMessageBox.Ok | QMessageBox.Cancel) # type of buttons associated
msg.buttonClicked.connect(myfunc) # connect clicked signal
return_value =msg.exec_() # get the return value
print("value of pressed message box button:", str(return_value)) # print result
Posted by: Guest on December-01-2020
0

pyqt5 file dialog example

import sys
from PyQt5.QtWidgets import QApplication, QMainWindow, QWidget, 
    QPushButton, QVBoxLayout, QFileDialog

# you can copy and run this code

class MainWindow(QMainWindow):
    def __init__(self, parent=None):#--------------
        super(MainWindow, self).__init__(parent)#  |
        self.setWindowTitle("open file dialog")#   |
#												   |
        btn = QPushButton("Open File")#            |---- Just initialization
        layout = QVBoxLayout()#					   |
        layout.addWidget(btn)#                     |
        widget = QWidget()#                        |
        widget.setLayout(layout)#                  |
        self.setCentralWidget(widget)#-------------

        btn.clicked.connect(self.open) # connect clicked to self.open()
        self.show()

    def open(self):
        path = QFileDialog.getOpenFileName(self, 'Open a file', '',
                                        'All Files (*.*)')
        if path != ('', ''):
            print("File path : "+ path[0])

if __name__ == "__main__":
    app = QApplication(sys.argv)
    window = MainWindow()
    sys.exit(app.exec_())
Posted by: Guest on December-05-2020
0

pyqt open file dialog

def open_file(self):
	def open(self):
        path = QFileDialog.getOpenFileName(self, 'Open a file', '',
                                        'All Files (*.*)')
        if path != ('', ''):
            print(path[0])
Posted by: Guest on December-05-2020
1

qmessagebox icon pyqt5

# Question
# Information
# Warning
# Critical

# Example:
msg.setIcon(QMessageBox.Information)
Posted by: Guest on December-01-2020

Python Answers by Framework

Browse Popular Code Answers by Language