我試圖在成功登錄後啓動系統托盤菜單。我有2 QtUi屏幕,其餘的只是Python代碼。首先登錄對話框,我想在登錄後隱藏這個對話框並顯示系統托盤菜單。這是我到目前爲止的代碼:PyQt4在登錄後立即啓動系統托盤圖標
注:UI_Login是QtDesigner
對話框1.系統托盤UI
from PyQt4 import QtGui
class SystemTrayIcon(QtGui.QSystemTrayIcon):
def __init__(self, icon, parent=None):
QtGui.QSystemTrayIcon.__init__(self, parent)
menu = QtGui.QMenu(parent)
self.exitAction = menu.addAction("Exit")
self.helpAction = menu.addAction("Help")
self.setIcon(icon)
self.setContextMenu(menu)
2.登錄功能。調用爲SystemTrayIcon
import sys
from PyQt4 import QtGui, QtCore
from modules.ui.login_ui import Ui_Login
from modules.ui.menu_ui import SystemTrayIcon
from api.auth import doLogin
class Login(QtGui.QDialog):
"""
Login user via the api
Links the gui and the app functionality
Logged user token is saved for further processing
"""
def __init__(self, parent = None):
QtGui.QDialog.__init__(self, parent)
self.ui = Ui_Login()
self.ui.setupUi(self)
self.ui.pushButton.clicked.connect(self.doLogin)
def doLogin(self):
self.password = unicode(self.ui.password.text())
self.email = unicode(self.ui.email.text())
request_data = {"username": ""+self.email+"", "password": ""+self.password+""}
response = doLogin(request_data)
if response.status_code == 200:
"""
1. Save Api token for future entries
2. Start app. i.e create a system tray app.
"""
self.token = response.json()['token'];
self.hide()
trayIcon = SystemTrayIcon(QtGui.QIcon("Bomb.xpm"))
trayIcon.show()
print "End check"
else:
#Raise error
print response.json()
3.主文件
import sys
from PyQt4 import QtGui, QtCore
from modules.login import Login
def main():
app = QtGui.QApplication(sys.argv)
login = Login()
login.show()
sys.exit(app.exec_())
if __name__ == "__main__":
main()
問題 - 系統托盤圖標沒有顯示出來,當登錄對話框關閉。
您的意見非常感謝。
謝謝,保存了我的一天,這讓我瞭解如何處理其他屏幕過渡。 非常感謝 –