PYQT4 Learning Notes-dialog box (update ing)

Source: Internet
Author: User
Tags first string

Qinputdialog: A dialog box that can interactively enter a single value. The input value can be a string, a number, or an item in the list.

#!/usr/bin/python#-*-coding:utf-8-*-ImportSYS fromPyQt4ImportQtgui fromPyQt4ImportQtcoreclassinputexample (qtgui.qwidget):def __init__(self): Super (Inputexample, self).__init__() Self.initui ()defInitui (self): Self.button= Qtgui.qpushbutton ('Dialog', self) self.button.setFocusPolicy (QtCore.Qt.NoFocus)#set the focus policy, Nofocus indicates that the focus is not acceptedSelf.button.move (20, 20) Self.connect (Self.button, Qtcore.signal ('clicked ()'), Self.showdialog) Self.setfocus ()#gets the focus after the signal is received (the component in the calling method)? Self.label=Qtgui.qlineedit (self) self.label.setFocusPolicy (QtCore.Qt.NoFocus)#set the focus policy, Nofocus indicates that the focus is not acceptedSelf.label.move (130, 22) Self.setwindowtitle ('Inputdialog') Self.setgeometry (300, 300, 350, 80)    defShowDialog (self):#Initialize input box, define input box title, prompt characterText, OK = QtGui.QInputDialog.getText (self,'Input Dialog',                                              'Enter your name:')        #OK in the above as the identification of if, and show the effect is irrelevant        #The input box shows the default is Ok,cancel        ifOk:self.label.setText (str (text))#If you click Confirm, the value entered will appear in the label aboveif __name__=='__main__': App=qtgui.qapplication (SYS.ARGV) ex=inputexample () ex.show () app.exec_ ( )

Qfiledialog: Allow users to select files or folders, select files to open and save

#!/usr/bin/python#-*-coding:utf-8-*-ImportSYS fromPyQt4ImportQtgui fromPyQt4ImportQtcoreclassopenfileexample (Qtgui.qmainwindow):def __init__(self): Super (Openfileexample, self).__init__() Self.initui ()defInitui (self): Self.textedit=Qtgui.qtextedit () self.setcentralwidget (Self.textedit) Self.statusbar () Self.setfocus () OpenFile= Qtgui.qaction (Qtgui.qicon ('Icons/open.png'),'Open', self) openfile.setshortcut ('Ctrl+o') Openfile.setstatustip ('Open New File') Self.connect (OpenFile, Qtcore.signal ('triggered ()'), self.showdialog) menubar=Self.menubar () Filemenu= Menubar.addmenu ('&file') filemenu.addaction (openFile) self.setgeometry (300, 300, 350, 300) Self.setwindowtitle ('OpenFile')    defShowDialog (self): filename= QtGui.QFileDialog.getOpenFileName (self,'Open File',                                                     ' /Home')        #The first string is the caption, the second string specifies the working directory of the dialog box, and home/home is also available under WindowsFName =open (filename)#can not directly open the path contains Chinese files, will errordata =Fname.read ()#Read Fileself.textEdit.setText (data)#display in a text fieldapp=qtgui.qapplication (SYS.ARGV) ex=openfileexample () ex.show () app.exec_ ( )

And then update it later.

PYQT4 Learning Notes-dialog box (update ing)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.