0
#!/usr/bin/python
#
# GUI.py
#
# Copyright 2015 Ognjen Galic <[email protected]>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
# MA 02110-1301, USA.
#
#
################################# UI START ############################
from PyQt4 import QtCore, QtGui
import sys
try:
_fromUtf8 = QtCore.QString.fromUtf8
except AttributeError:
def _fromUtf8(s):
return s
try:
_encoding = QtGui.QApplication.UnicodeUTF8
def _translate(context, text, disambig):
return QtGui.QApplication.translate(context, text, disambig, _encoding)
except AttributeError:
def _translate(context, text, disambig):
return QtGui.QApplication.translate(context, text, disambig)
class Ui_MainWindow(object):
def setupUi(self, MainWindow):
MainWindow.setObjectName(_fromUtf8("MainWindow"))
MainWindow.resize(200, 100)
MainWindow.setWindowTitle(_fromUtf8("Example"))
self.main_widget = QtGui.QWidget(MainWindow)
self.main_widget.setObjectName(_fromUtf8("main_widget"))
self.horizontalLayout = QtGui.QHBoxLayout(self.main_widget)
self.horizontalLayout.setObjectName(_fromUtf8("horizontalLayout"))
self.exit_button = QtGui.QPushButton(self.main_widget)
self.exit_button.setObjectName(_fromUtf8("exit_button"))
self.horizontalLayout.addWidget(self.exit_button)
self.trayIcon = QtGui.QSystemTrayIcon(QtGui.QIcon("icon.png")) # <<<<<<<<<<< WONT SHOW
MainWindow.setCentralWidget(self.main_widget)
self.retranslateUi(MainWindow)
QtCore.QMetaObject.connectSlotsByName(MainWindow)
# --------------------------- QT ACTION BIND START #############
self.exit_button.clicked.connect(self.exit_main)
# --------------------------- QT ACTION BIND STOP ##############
def retranslateUi(self, MainWindow):
self.exit_button.setText(_translate("MainWindow", "Exit", None))
# --------------------------- MAIN FUNCTIONS START #############
def exit_main(self):
sys.exit()
# --------------------------- MAIN FUNCTIONS STOP ##############
def initUI():
app = QtGui.QApplication(sys.argv)
MainWindow = QtGui.QMainWindow()
ui = Ui_MainWindow()
ui.setupUi(MainWindow)
MainWindow.show()
sys.exit(app.exec_())
################################### UI STOP ###########################
def main():
pass
initUI() # Initialize the UI
main() # Run the MAIN
這裏是我的源,Python是2.7,AMD64,Ubuntu的16.04 Xenial Xerus而且Xfce 4.12,PyQt4的的PyQt沒有顯示QSystemTrayIcon上XFCE/Ubuntu的16.04 Xenial Xerus
的那樣是爲了顯示系統托盤圖標:
self.trayIcon = QtGui.QSystemTrayIcon(QtGui.QIcon("icon.png"))
無所事事。然而,如果在手動trayIcon.show()
的另一個.py文件上運行,它可以正常工作。
還在學習,和我一起裸露,但沒有看到理由它無法工作。
謝謝。
尼斯。它工作很好。我很白癡,我錯過了。謝謝! – Gala