Zetcode PyQt4 Tutorial work with menus, toolbars, a statusbar, and a main application window

Source: Internet
Author: User

!/usr/bin/python-*-Coding:utf-8-*-"""Zetcode PYQT4 Tutorial This program creates a Statusbar.author:Jan Bodnarwebsite:zetcode.com last Edited:september ."""ImportSYS fromPyQt4ImportQtguiclassExample (Qtgui.qmainwindow):def __init__(self):#Super (type[, Object-or-type]): Return A proxy object, delegates method calls to a parent or sibling class of type .Super (Example, self).__init__() Self.initui ()defInitui (self):#to get the StatusBar, we call the StatusBar () method of the Qtgui.qmainwindow class. The first call of the method creates a status bar. Subsequent calls return the StatusBar object. The ShowMessage () displays a message on the statusbar.Self.statusbar (). ShowMessage (' Ready') Self.setgeometry (300, 300, 250, 150) Self.setwindowtitle ('Statusbar') self.show ()defMain (): App=qtgui.qapplication (SYS.ARGV) ex=Example () sys.exit (App.exec_ ())if __name__=='__main__': Main ()--------------------------------------------------------------------------------#!/usr/bin/python#-*-coding:utf-8-*-"""Zetcode PYQT4 Tutorial This program creates a menubar. Themenubar have one menu with a exit Action.author:Jan Bodnarwebsite:zetcode.com last Edited:august"""ImportSYS fromPyQt4ImportQtguiclassExample (Qtgui.qmainwindow):def __init__(self): Super (Example, self).__init__() Self.initui ()defInitui (self):#A Qtgui.qaction is an abstraction for actions performed with a menubar, toolbar or with a custom keyboard shortcut. I n The above three lines, we create an action with a specific icon and a ' Exit ' label. Furthermore, a shortcut is defined for the this action. The third line creates a status tip which are shown in the statusbar when we hover a mouse pointer over the menu item.Exitaction = Qtgui.qaction (Qtgui.qicon ('Exit.png'),'&exit', self) exitaction.setshortcut ('Ctrl+q') Exitaction.setstatustip ('Exit Application')        #When we select the particular action, a triggered signal is emitted. The signal is connected to the Quit () method of the Qtgui.qapplication widget. This terminates the application.ExitAction.triggered.connect (QtGui.qApp.quit) Self.statusbar ()#The MenuBar () method creates a menuBar. We Create a File menu and append the exit action to it.menubar =Self.menubar () Filemenu= Menubar.addmenu ('&file') filemenu.addaction (exitaction) self.setgeometry (300, 300, 300, 200) Self.setwindowtitle ('Menubar') self.show ()defMain (): App=qtgui.qapplication (SYS.ARGV) ex=Example () sys.exit (App.exec_ ())if __name__=='__main__': Main ()-------------------------------------------------------------------------------#!/usr/bin/python#-*-coding:utf-8-*-"""Zetcode PYQT4 Tutorial This program creates a toolbar. The toolbar have one action, whichterminates the application if Triggered.author:Jan Bodnarwebsite:zetcode.com last Edite D:september"""ImportSYS fromPyQt4ImportQtguiclassExample (Qtgui.qmainwindow):def __init__(self): Super (Example, self).__init__() Self.initui ()defInitui (self):#Similar to the menubar example above, we create an action object. The object has a label, icon and a shorcut. A quit () method of the Qtgui.qmainwindow is connected to the triggered signal.Exitaction = Qtgui.qaction (Qtgui.qicon ('Exit24.png'),'Exit', self) exitaction.setshortcut ('Ctrl+q') ExitAction.triggered.connect (QtGui.qApp.quit)#Here we create a toolbar and Plug and Action object into it.Self.toolbar = Self.addtoolbar ('Exit') self.toolbar.addAction (exitaction) self.setgeometry (300, 300, 300, 200) Self.setwindowtitle ('Toolbar') self.show ()defMain (): App=qtgui.qapplication (SYS.ARGV) ex=Example () sys.exit (App.exec_ ())if __name__=='__main__': Main ()--------------------------------------------------------------------------------#!/usr/bin/python#-*-coding:utf-8-*-"""Zetcode PYQT4 Tutorial This program creates a skeleton OFA classic GUI application with a menubar,toolbar, StatusBar a nd a central widget. Author:jan Bodnarwebsite:zetcode.com last Edited:september"""ImportSYS fromPyQt4ImportQtguiclassExample (Qtgui.qmainwindow):def __init__(self): Super (Example, self).__init__() Self.initui ()defInitui (self):#Here we create a text edit widget. We set it to being the central widget of the Qtgui.qmainwindow. the central widget, occupies all space, is left.TextEdit =Qtgui.qtextedit () self.setcentralwidget (textEdit) exitaction= Qtgui.qaction (Qtgui.qicon ('Exit24.png'),'Exit', self) exitaction.setshortcut ('Ctrl+q') Exitaction.setstatustip ('Exit Application') ExitAction.triggered.connect (self.close) Self.statusbar () MenuBar=Self.menubar () Filemenu= Menubar.addmenu ('&file') filemenu.addaction (exitaction) toolbar= Self.addtoolbar ('Exit') toolbar.addaction (exitaction) self.setgeometry (300, 300, 350, 250) Self.setwindowtitle ('Main window') self.show ()defMain (): App=qtgui.qapplication (SYS.ARGV) ex=Example () sys.exit (App.exec_ ())if __name__=='__main__': Main ()

Zetcode PyQt4 Tutorial work with menus, toolbars, a statusbar, and a main application window

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.