Build Notepad interface with PYQT5
1 #-*-coding:utf-8-*-2 """3 Introduction: Use PYQT5 to make a dialog box, there is a menu (2, there is a separate icon, shortcut), the cue bar (only the main window has a prompt bar), exit with two times confirmation4 ideas: References and refactoring methods in PyQt55 6 thinking: PYQT5 requires that the component be built before it is called, but the connection object can be placed behind7 """8 9 Ten ImportSYS One fromPyqt5.qtwidgetsImportQapplication,qmainwindow,qaction,qmessagebox#introduce the whole component, main window, action, pop-up box (at the end of the page, above the top, must be processed first) A fromPyqt5.qtguiImportQicon - - the classMywin (Qmainwindow):#The new definition class is a class that inherits and Reconstructs Qmainwindow this method - def __init__(self):#It's not moving here . -Super ().__init__() -Self.initui ()#Initui () This method reconstructs + - #create an Action object and set + defInitui (self): A at #Action------------------------------------------------------------ - #file _ New -Action_buliding=qaction (Qicon ('1.ico'),'& New (N)', self) -Action_buliding.setshortcut ('CTRL + N') -Action_buliding.setstatustip ('Create a new text file')#prompt, default no -Action_buliding.triggered.connect (Self.open)#Link to open action------------ in #File _ Open -Action_open=qaction (Qicon ('1.ico'),'& Open (O)', self) toAction_open.setshortcut ('Ctrl+o') +Action_open.triggered.connect (Self.open)#Link to open action------------ - #File _ Save theAction_save = Qaction (Qicon ('1.ico'),'& Open (O)', self) *Action_save.setshortcut ('Ctrl+o') $Action_save.triggered.connect (Self.open)#Link to open action------------Panax Notoginseng #file _ Save as -Action_other_save = Qaction (Qicon ('1.ico'),'& Save As (A)', self) theAction_other_save.triggered.connect (Self.open)#Link to open action------------ + #File _ page Design AAction_page_design = Qaction (Qicon ('1.ico'),'& Page Design', self) theAction_page_design.triggered.connect (Self.open)#Link to open action------------ + #File _ Print -Action_page_print = Qaction (Qicon ('1.ico'),'& Printing', self) $Action_page_print.triggered.connect (Self.open)#Link to open action------------ $ #File _ Exit -Action_close=qaction (Qicon ('1.ico'),'& Exit', self) -Action_close.setshortcut ('A') theAction_close.setstatustip ('This is the Exit Function') - Action_close.triggered.connect (self.close)Wuyi the #Menu Bar------------------------------------------------------------------------- -Menubar=Self.menubar () WuMenufile=menubar.addmenu ('& Document (F)') -Menufile.addaction (action_buliding)#New AboutMenufile.addaction (Action_open)#Open $Menufile.addaction (Action_save)#Save -Menufile.addaction (Action_other_save)#Save As -Menufile.addaction (action_page_design)#Page Setup -Menufile.addaction (Action_page_print)#Print AMenufile.addaction (Action_close)#Exit + theMenuBar =Self.menubar () -Menufile = Menubar.addmenu ('& Editor (E)') $ menufile.addaction (Action_open) the theMenuBar =Self.menubar () theMenufile = Menubar.addmenu ('& Format (O)') the menufile.addaction (Action_open) - inMenuBar =Self.menubar () theMenufile = Menubar.addmenu ('& View (V)') the menufile.addaction (Action_open) About theMenuBar =Self.menubar () theMenufile = Menubar.addmenu ('& Help (H)') the menufile.addaction (Action_open) + - #(new) Create toolbar------------------------------------------------------------------- the #Toolbar=self.addtoolbar ("Exit")Bayi #toolbar.addaction (action_open***) #与上面的动作重复, need to change an action or temporarily drop the above the the - #Toolbar=self.addtoolbar ("Exit") - #toolbar.addaction (action_close***) #与上面的动作重复, need to change an action or temporarily drop the above the the #Set the status bar theSelf.statusbar (). ShowMessage ('This is the status bar, which shows the amount of work in progress in real time ....') the - #Setting window Properties theSelf.setgeometry (100,300,400,400)#Geometry Geometry theSelf.setwindowtitle ('Create a new text document') theSelf.setwindowicon (Qicon ('1.ico'))94Self.show ()#window display mode-block process, and then close when there is an end signal the the defCloseevent (self,event):#Close the #gets the value of the message box instance98Msg=qmessagebox.question (Self,'Exit Warning','Are you sure you want to quit? ', Qmessagebox.yes |qmessagebox.no,qmessagebox.no) About #determining the return value of a message box - ifmsg==Qmessagebox.yes:101 event.accept ()102 Else:103 Event.ignore ()104 defOpen (self): the Print('This is the act of acting.')106 #Main Method107 if __name__=='__main__':108app=qapplication (SYS.ARGV)109my=Mywin () theSys.exit (App.exec_ ())
Pyqt5_notepad Interface
Python_ using PYQT5 to build Notepad interface