這篇文章主要為大家詳細介紹了Python PyQt4實現QQ抽屜效果,具有一定的參考價值,有興趣的小夥伴們可以參考一下
本文實例為大家分享了Python PyQt4實現QQ抽屜效果展示的具體程式碼,供大家參考,具體內容如下
先看截圖效果:
主要是使用了QT的QTabWidget、QToolBox多頁面視窗元件
# -*- coding: utf-8 -*- from PyQt4.QtGui import * from PyQt4.QtCore import * import sys QTextCodec.setCodecForTr(QTextCodec.codecForName("utf8")) class MyQQ(QTabWidget): def __init__(self,parent=None): super(MyQQ,self).__init__(parent) toolButton1=QToolButton() toolButton1.setText(self.tr("gavin")) toolButton1.setIcon(QIcon("d:/image/1.png")) toolButton1.setIconSize(QSize(60,60)) toolButton1.setAutoRaise(True) toolButton1.setToolButtonStyle(Qt.ToolButtonTextBesideIcon) toolButton2=QToolButton() toolButton2.setText(self.tr("问题的方法")) toolButton2.setIcon(QIcon("d:/image/2.png")) toolButton2.setIconSize(QSize(60,60)) toolButton2.setAutoRaise(True) toolButton2.setToolButtonStyle(Qt.ToolButtonTextBesideIcon) toolButton3=QToolButton() toolButton3.setText(self.tr("为什么")) toolButton3.setIcon(QIcon("d:/image/3.png")) toolButton3.setIconSize(QSize(60,60)) toolButton3.setAutoRaise(True) toolButton3.setToolButtonStyle(Qt.ToolButtonTextBesideIcon) groupbox1=QGroupBox() vlayout1=QVBoxLayout(groupbox1) vlayout1.setMargin(10) vlayout1.setAlignment(Qt.AlignCenter) vlayout1.addWidget(toolButton1) vlayout1.addWidget(toolButton2) vlayout1.addStretch() groupbox2=QGroupBox() vlayout2=QVBoxLayout(groupbox2) vlayout2.setMargin(10) vlayout2.setAlignment(Qt.AlignCenter) vlayout2.addWidget(toolButton3) vlayout2.addStretch() groupbox3=QGroupBox() toolbox1 = QToolBox() toolbox1.addItem(groupbox1,self.tr("我的好友")) toolbox1.addItem(groupbox2,self.tr("同事")) toolbox1.addItem(groupbox3,self.tr("黑名单")) toolbox2 = QToolBox() self.addTab(toolbox1, "联系人") self.addTab(toolbox2, "群/讨论组") app=QApplication(sys.argv) myqq=MyQQ() myqq.setWindowTitle("QQ2012") myqq.show() app.exec_()
#問題記錄
#1.腳本中使用中文處,提示錯誤:
SyntaxError:b8ac6eb524c94f74f8b3ff6676594678 'utf8' codec can't decode byte 0xc4 in position 0: invalid continuation byte
#需要將*.py檔案儲存成utf-8, 我用的是gvim,一直沒搞明白vim的編碼設置,所以我用了種比較笨的方法,用記事本打開,另存為utf-8格式
2.一開始,我把頭像目錄image放在\Python32\Lib\site-packages目錄下,然後在解釋中呼叫模組,但不能顯示,後來就改用了絕對路徑
以上是Python PyQt4實現QQ抽屜效果的詳細內容。更多資訊請關注PHP中文網其他相關文章!