最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

python+PyQT實(shí)現(xiàn)系統(tǒng)桌面時(shí)鐘

 更新時(shí)間:2020年06月16日 10:15:26   作者:智元元  
這篇文章主要為大家詳細(xì)介紹了python+PyQT實(shí)現(xiàn)系統(tǒng)桌面時(shí)鐘,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

用Python + PyQT寫的一個(gè)系統(tǒng)桌面時(shí)鐘,剛學(xué)習(xí)Python,寫的比較簡陋,但是基本的功能還可以。

功能:

①窗體在應(yīng)用程序最上層,不用但是打開其他應(yīng)用后看不到時(shí)間

②左鍵雙擊全屏,可以做小屏保使用,再次雙擊退出全屏。

③系統(tǒng)托盤圖標(biāo),主要參考PyQt4源碼目錄中的PyQt4\examples\desktop\systray下的程序

④鼠標(biāo)右鍵,將程序最小化

使用時(shí)需要heart.svg放在源代碼同級目錄下,[文件可在PyQt4示例代碼目錄下PyQt4\examples\desktop\systray\images找到

運(yùn)行需要Python2.7 + PyQt4.

__metaclass__ = type 
#!coding= utf-8 
#http://blog.csdn.net/gatieme/article/details/17659259 
#gatieme 
 
 
import sys 
from PyQt4.QtCore import * 
from PyQt4.QtGui import * 
 
 
#-------------------------------------------------------------------------------- 
class SystemTrayIcon(QSystemTrayIcon): 
 """ 
 The systemTrayIcon which uesd to connect the clock 
 """ 
 #---------------------------------------------------------------------------- 
 def __init__(self, mainWindow, parent = None): 
  """ 
  mainWindow : the main window that the system tray icon serves to 
  """  
  super(SystemTrayIcon, self).__init__(parent) 
  self.window = mainWindow 
  self.setIcon(QIcon("heart.svg")) # set the icon of the systemTrayIcon 
   
  self.createActions( ) 
  self.createTrayMenu( ) 
   
  self.connect(self, SIGNAL("doubleClicked"), self.window, SLOT("showNormal")) 
  #self.connect(self, SIGNAL("activated( )"), self, SLOT("slot_iconActivated")) 
   
 
 def createActions(self): 
  """ 
  create some action to Max Min Normal show the window 
  """ 
  self.minimizeAction = QAction("Mi&nimize", self.window, triggered = self.window.hide) 
  self.maximizeAction = QAction("Ma&ximize", self.window, triggered = self.window.showMaximized) 
  self.restoreAction = QAction("&Restore", self.window, triggered = self.window.showNormal) 
  self.quitAction = QAction("&Quit", self.window, triggered = qApp.quit) 
     
 
 def createTrayMenu(self): 
   self.trayIconMenu = QMenu(self.window) 
   self.trayIconMenu.addAction(self.minimizeAction) 
   self.trayIconMenu.addAction(self.maximizeAction) 
   self.trayIconMenu.addAction(self.restoreAction) 
   self.trayIconMenu.addSeparator( ) 
   self.trayIconMenu.addAction(self.quitAction) 
 
   self.setContextMenu(self.trayIconMenu) 
  
 def setVisible(self, visible): 
  self.minimizeAction.setEnabled(not visible) 
  self.maximizeAction.setEnabled(not self.window.isMaximized()) 
  self.restoreAction.setEnabled(self.window.isMaximized() or not visible) 
  super(Window, self).setVisible(visible) 
 
 
 
 def closeEvent(self, event): 
  #if event.button( ) == Qt.RightButton: 
  self.showMessage("Message", 
    "The program will keep running in the system tray. To " 
    "terminate the program, choose <b>Quit</b> in the " 
    "context menu of the system tray entry.", 
    QSystemTrayIcon.Information, 5000) 
  self.window.hide( ) 
  event.ignore( ) 
 
 def slot_iconActivated(self, reason): 
  if reason == QSystemTrayIcon.DoubleClick: 
   self.wiondow.showNormal( ) 
 
 
 
#-------------------------------------------------------------------------------- 
class DigitClock(QLCDNumber): 
 """ 
 the DigitClock show a digit clock int the printer 
 """ 
  
 #---------------------------------------------------------------------------- 
 def __init__(self, parent = None): 
  """ 
  the constructor function of the DigitClock 
  """ 
  super(DigitClock, self).__init__(parent) 
  pale = self.palette( ) 
 
  pale.setColor(QPalette.Window, QColor(100, 180, 100)) 
  self.setPalette(pale) 
   
  self.setNumDigits(19) 
  self.systemTrayIcon = SystemTrayIcon(mainWindow = self) 
 
   
  self.dragPosition = None; 
  self.setWindowFlags(Qt.FramelessWindowHint | Qt.WindowStaysOnTopHint | Qt.Popup | Qt.Tool) 
  self.setWindowOpacity(1) 
   
  self.showTime( )   # print the time when the clock show 
  self.systemTrayIcon.show( ) # show the SystemTaryIcon when the clock show 
 
  self.timer = QTimer( ) 
  self.connect(self.timer, SIGNAL("timeout( )"), self.showTime) 
  self.timer.start(1000) 
   
  self.resize(500, 60) 
   
  
 #---------------------------------------------------------------------------- 
 def showTime(self): 
  """ 
  show the current time 
  """ 
  self.date = QDate.currentDate( ) 
  self.time = QTime.currentTime( ) 
  text = self.date.toString("yyyy-MM-dd") + " " + self.time.toString("hh:mm:ss") 
  self.display(text) 
 
   
 
 #---------------------------------------------------------------------------- 
 def mousePressEvent(self, event): 
  """ 
  clicked the left mouse to move the clock 
  clicked the right mouse to hide the clock 
  """ 
  if event.button( ) == Qt.LeftButton: 
   self.dragPosition = event.globalPos( ) - self.frameGeometry( ).topLeft( ) 
   event.accept( ) 
  elif event.button( ) == Qt.RightButton: 
   self.systemTrayIcon.closeEvent(event) 
 
   #self.systemTrayIcon.hide( ) 
   #self.close( ) 
 
 def mouseMoveEvent(self, event): 
  """ 
  """ 
  if event.buttons( ) & Qt.LeftButton: 
   self.move(event.globalPos( ) - self.dragPosition) 
   event.accept( ) 
  
 def keyPressEvent(self, event): 
  """ 
  you can enter "ESC" to normal show the window, when the clock is Maxmize 
  """ 
  if event.key() == Qt.Key_Escape and self.isMaximized( ): 
   self.showNormal( ) 
 
 def mouseDoubleClickEvent(self, event): 
  """ 
  """ 
  if event.buttons() == Qt.LeftButton: 
   if self.isMaximized( ): 
    self.showNormal( ) 
   else: 
    self.showMaximized( ) 
  
if __name__ == "__main__": 
 app = QApplication(sys.argv) 
  
 digitClock = DigitClock( ) 
 digitClock.show( )  
  
 sys.exit(app.exec_( )) 

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • 詳解python while 函數(shù)及while和for的區(qū)別

    詳解python while 函數(shù)及while和for的區(qū)別

    這篇文章主要介紹了python while 函數(shù)及while和for的區(qū)別 ,本文給大家介紹的非常詳細(xì),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2018-09-09
  • Python中DataFrame轉(zhuǎn)列表的最全指南

    Python中DataFrame轉(zhuǎn)列表的最全指南

    在Python數(shù)據(jù)分析中,Pandas的DataFrame是最常用的數(shù)據(jù)結(jié)構(gòu)之一,本文將為你詳解5種主流DataFrame轉(zhuǎn)換為列表的方法,大家可以根據(jù)需求進(jìn)行選擇
    2025-03-03
  • 淺談Python模塊導(dǎo)入規(guī)范

    淺談Python模塊導(dǎo)入規(guī)范

    這篇文章主要介紹了淺談Python模塊導(dǎo)入規(guī)范,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2021-04-04
  • python刪除不需要的python文件方法

    python刪除不需要的python文件方法

    下面小編就為大家分享一篇python刪除不需要的python文件方法,具有很好的參考價(jià)值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2018-04-04
  • Python運(yùn)算符的使用簡單介紹

    Python運(yùn)算符的使用簡單介紹

    這篇文章主要介紹了Python運(yùn)算符的使用簡單介紹,文章圍繞主題展開詳細(xì)的內(nèi)容介紹,具有一定的參考價(jià)值,需要的朋友可以參考一下
    2022-08-08
  • python+PyQT實(shí)現(xiàn)系統(tǒng)桌面時(shí)鐘

    python+PyQT實(shí)現(xiàn)系統(tǒng)桌面時(shí)鐘

    這篇文章主要為大家詳細(xì)介紹了python+PyQT實(shí)現(xiàn)系統(tǒng)桌面時(shí)鐘,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2018-11-11
  • Django封裝交互接口代碼

    Django封裝交互接口代碼

    這篇文章主要介紹了Django封裝交互接口代碼,具有很好的參考價(jià)值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2020-07-07
  • pycharm中使用request和Pytest進(jìn)行接口測試的方法

    pycharm中使用request和Pytest進(jìn)行接口測試的方法

    這篇文章主要介紹了pycharm中使用request和Pytest進(jìn)行接口測試的方法,本文給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2020-07-07
  • 用python爬取豆瓣前一百電影

    用python爬取豆瓣前一百電影

    大家好,本篇文章主要講的是用python爬取豆瓣前一百電影,感興趣的同學(xué)趕快來看一看吧,對你有幫助的話記得收藏一下
    2022-01-01
  • 分享十個(gè)Python提高工作效率的自動(dòng)化腳本

    分享十個(gè)Python提高工作效率的自動(dòng)化腳本

    在這個(gè)自動(dòng)化時(shí)代,我們有很多重復(fù)無聊的工作要做。 想想這些你不再需要一次又一次地做的無聊的事情,讓它自動(dòng)化,讓你的生活更輕松。本文分享了10個(gè)Python自動(dòng)化腳本,希望對大家有所幫助
    2022-10-10

最新評論

玉田县| 嘉禾县| 任丘市| 永平县| 嵩明县| 万全县| 永平县| 驻马店市| 吉安市| 沙湾县| 桃园县| 五河县| 西充县| 什邡市| 峨眉山市| 新田县| 江孜县| 黄龙县| 阿拉尔市| 读书| 交城县| 梓潼县| 舟山市| 额敏县| 黄浦区| 鄂托克旗| 大兴区| 富民县| 三都| 磐安县| 黄冈市| 青浦区| 广东省| 门源| 孝昌县| 达州市| 梁河县| 灵川县| 阳西县| 长武县| 湘西|