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)