簡體   English   中英

PyQt5中的問號按鈕

[英]Question mark button in PyQt5

單擊問號按鈕時如何顯示消息框? 我從帖子中嘗試了一些代碼,但是沒有用。

問號:

圖片

QMessageBox是一個常用的模態對話框,用於顯示一些參考消息,並有選擇地要求用戶通過單擊其上的任一標准按鈕來做出響應。 每個標准按鈕都有一個預定義的標題,一個角色並返回預定義的十六進制數字。

下表給出了與QMessageBox類關聯的重要方法和枚舉-

S.No.        Methods & Description

setIcon()    Displays predefined icon corresponding to severity of the message

Question     Question

Information Information

Warning     Warning

Critical     Critical

setText()    Sets the text of the main message to be displayed

setInformativeText() Displays additional information

setDetailText()  Dialog shows a Details button. This text appears on clicking it

setTitle()  Displays the custom title of dialog


setStandardButtons()  List of standard buttons to be displayed. Each button is associated with

QMessageBox.Ok 0x00000400

QMessageBox.Open 0x00002000

QMessageBox.Save 0x00000800

QMessageBox.Cancel 0x00400000

QMessageBox.Close 0x00200000

QMessageBox.Yes 0x00004000

QMessageBox.No 0x00010000

QMessageBox.Abort 0x00040000

QMessageBox.Retry 0x00080000

QMessageBox.Ignore 0x00100000


setDefaultButton()  Sets the button as default. It emits the clicked signal if Enter is pressed

setEscapeButton()  Sets the button to be treated as clicked if the escape key is pressed

這里直接

import sys
from PyQt4.QtGui import *
from PyQt4.QtCore import *

def window():
   app = QApplication(sys.argv)
   w = QWidget()
   b = QPushButton(w)
   b.setText("Show message!")

  b.move(50,50)
   b.clicked.connect(showdialog)
   w.setWindowTitle("PyQt Dialog demo")
   w.show()
   sys.exit(app.exec_())

def showdialog():
   msg = QMessageBox()
  msg.setIcon(QMessageBox.Information)

   msg.setText("This is a message box")
   msg.setInformativeText("This is additional     information")
   msg.setWindowTitle("MessageBox demo")
  msg.setDetailedText("The details are as follows:")
   msg.setStandardButtons(QMessageBox.Ok | 
QMessageBox.Cancel)
   msg.buttonClicked.connect(msgbtn)

   retval = msg.exec_()
   print "value of pressed message box button:", retval

def msgbtn(i):
   print "Button pressed is:",i.text()

if __name__ == '__main__': 
   window()

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM