Created
January 2, 2021 12:28
-
-
Save Park-Developer/1f5a5c283d0bba037c5dfcd8d5f6d572 to your computer and use it in GitHub Desktop.
pyqt5 : input dialog
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
import sys | |
from PyQt5.QtWidgets import QApplication, QWidget, QInputDialog, QLineEdit | |
from PyQt5.QtGui import QIcon | |
class App(QWidget): | |
def __init__(self): | |
super().__init__() | |
self.title = 'PyQt5 input dialogs - pythonspot.com' | |
self.left = 10 | |
self.top = 10 | |
self.width = 640 | |
self.height = 480 | |
self.initUI() | |
def initUI(self): | |
self.setWindowTitle(self.title) | |
self.setGeometry(self.left, self.top, self.width, self.height) | |
self.getInteger() | |
self.getText() | |
self.getDouble() | |
self.getChoice() | |
self.show() | |
def getInteger(self): | |
i, okPressed = QInputDialog.getInt(self, "Get integer", "Percentage:", 28, 0, 100, 1) | |
if okPressed: | |
print(i) | |
def getDouble(self): | |
d, okPressed = QInputDialog.getDouble(self, "Get double", "Value:", 10.50, 0, 100, 10) | |
if okPressed: | |
print(d) | |
def getChoice(self): | |
items = ("Red", "Blue", "Green") | |
item, okPressed = QInputDialog.getItem(self, "Get item", "Color:", items, 0, False) | |
print(item) | |
def getText(self): | |
text, okPressed = QInputDialog.getText(self, "Get text", "Your name:", QLineEdit.Normal, "") | |
if okPressed and text != '': | |
print(text) | |
if __name__ == '__main__': | |
app = QApplication(sys.argv) | |
ex = App() | |
sys.exit(app.exec_()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment