Last active
October 11, 2017 16:49
-
-
Save tcrowson/8152683242018378a00b to your computer and use it in GitHub Desktop.
Examples of simple PySide dialogs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from PySide.QtGui import * | |
# create a modal message box with a single 'Ok' button | |
box = QMessageBox() | |
box.setWindowTitle('Title') | |
box.setText('Text') | |
box.exec_() | |
# create a modal message box that offers some choices (Yes|No|Cancel) | |
box = QMessageBox() | |
box.setWindowTitle('Some Message') | |
box.setText("Pushing a button will do something.") | |
box.setInformativeText("Do you want to push a button?") | |
box.setStandardButtons(QMessageBox.Yes | QMessageBox.No | QMessageBox.Cancel) | |
box.setDefaultButton(QMessageBox.Save) | |
result = box.exec_() | |
if result == QMessageBox.Cancel: | |
print 'User pressed Cancel' | |
elif result == QMessageBox.No: | |
print 'User pressed No' | |
elif result == QMessageBox.Yes: | |
print 'User pressed Yes' | |
# Create a simple text input pop-up | |
text, okPressed = QInputDialog.getText(None, 'Window Title', 'Please type something...') | |
if okPressed: | |
print text | |
# Create a pop-up with a drop-down list of items to choose from | |
items = ['option 1', 'option 2', 'option 3', 'option 4'] | |
choice, okPressed = QInputDialog.getItem(None, 'Window Title', 'Please choose something...', items) | |
if okPressed: | |
print choice | |
# open a file requester for a single file | |
filename, nill = QFileDialog.getOpenFileName(None, 'Choose a file', '/home', "Image Files (*.png *.jpg *.bmp)") | |
# open a file requester for multiple files | |
filenames, nill = QFileDialog.getOpenFileName(None, 'Choose some files', '/home', "Image Files (*.png *.jpg *.bmp)") | |
# open a file requester for a directory | |
folder = QFileDialog.getExistingDirectory(None, 'Choose a folder', '/home') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment