zoukankan      html  css  js  c++  java
  • 对话框——输入对话框

     1 # !/usr/bin/python3
     2 # -*- coding: utf-8 -*-
     3 
     4 """
     5 ZetCode PyQt5 tutorial
     6 
     7 In this example, we receive data from
     8 a QInputDialog dialog.
     9 
    10 Aauthor: Jan Bodnar
    11 Website: zetcode.com
    12 Last edited: August 2017
    13 """
    14 
    15 from PyQt5.QtWidgets import (QWidget, QPushButton, QLineEdit, QInputDialog, QApplication)
    16 import sys
    17 
    18 
    19 class Example(QWidget):
    20 
    21     def __init__(self):
    22         super().__init__()
    23 
    24         self.initUI()
    25 
    26     def initUI(self):
    27 
    28         self.btn = QPushButton('Dialog', self)
    29         self.btn.move(20, 20)
    30         self.btn.clicked.connect(self.showDialog)
    31 
    32         self.le = QLineEdit(self)
    33         self.le.move(130, 22)
    34 
    35         self.setGeometry(300, 300, 290, 150)
    36         self.setWindowTitle('Input dialog')
    37         self.show()
    38 
    39     def showDialog(self):
    40 
    41         # The dialog returns the entered text and a boolean value.
    42         # if we click the Ok button, the boolean value is true
    43         # The first string is a dialog title, the second one is a message within the dialog
    44         text, ok = QInputDialog.getText(self, 'Input Dialog', 'Enter your name:')
    45 
    46         if ok:
    47             # The text that we have received from the dialog is 
    48             # set to the line edit widget with setText()
    49             self.le.setText(str(text))
    50 
    51 
    52 if __name__ == '__main__':
    53 
    54     app = QApplication(sys.argv)
    55     ex = Example()
    56     sys.exit(app.exec_())
  • 相关阅读:
    winfrom 获取当前系统时间
    netcore3.1API+efcore快速搭建
    php
    php
    php
    php-array的相关函数使用
    php-正则表达式
    vim的复制与粘贴
    vim的多窗口和文件切换操作
    laravel教程中出现500问题
  • 原文地址:https://www.cnblogs.com/fuqia/p/8734758.html
Copyright © 2011-2022 走看看