这里有新鲜出炉的Python多线程编程,程序狗速度看过来!
Python 是一种面向对象、解释型计算机程序设计语言,由Guido van Rossum于1989年底发明,第一个公开发行版发行于1991年。Python语法简洁而清晰,具有丰富和强大的类库。它常被昵称为胶水语言,它能够把用其他语言制作的各种模块(尤其是C/C++)很轻松地联结在一起。
这篇文章主要为大家详细介绍了python实现分页效果,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
难点:清空Layout
- #!/usr/bin/python
- #-*-coding:utf-8-*-
- from PyQt4.QtCore import *
- from PyQt4.QtGui import *
- class PageWidget(QWidget):
- def __init__(self,parent=None):
- super(PageWidget,self).__init__(parent)
- self.btns=[]
- self.count=0
- self.presign=0 #当前点击标识
- self.nextsign=0 #当前点击标识
- self.pre_button=QPushButton()
- self.pre_button.setText("<<")
- self.pre_button.setFixedSize(25,25)
- self.connect(self.pre_button,SIGNAL("clicked()"),self,SLOT("prepage()"))
- self.next_button=QPushButton()
- self.next_button.setText(">>")
- self.connect(self.next_button,SIGNAL("clicked()"),self,SLOT("nextpage()"))
- self.next_button.setFixedSize(25,25)
- self.center_layout=QHBoxLayout()
- self.nextpage()
- self.page_layput=QHBoxLayout()
- self.page_layput.addWidget(self.pre_button)
- self.page_layput.addLayout(self.center_layout)
- self.page_layput.addWidget(self.next_button)
- self.setLayout(self.page_layput)
- @pyqtSlot()
- def prepage(self):
- self.presign=1
- self.num=0
- if (len(self.btns)>0) and (self.count>=10):
- for p in range(10):
- self.center_layout.removeWidget(self.btns[p])
- self.btns[p].deleteLater()
- self.btns=[]
- if self.count>=10:
- if self.nextsign==1:
- self.count=self.count-20
- self.nextsign=0
- else:
- self.count=self.count-10
- self.num=self.count
- for i in range(10):
- self.num+=1
- self.center_button=QPushButton()
- self.center_button.setText(str(self.num))
- self.center_button.setFixedSize(25,25)
- self.btns.append(self.center_button)
- self.center_layout.addWidget(self.center_button)
- #print self.count
- @pyqtSlot()
- def nextpage(self):
- self.nextsign=1
- if len(self.btns)>0:
- for p in range(10):
- self.center_layout.removeWidget(self.btns[p])
- self.btns[p].deleteLater()
- self.btns=[]
- if self.presign==1:
- self.count=self.count+10
- self.presign=0
- #mapper转有参数
- signal_mapper = QSignalMapper(self)
- for i in range(10):
- self.count+=1
- self.center_button=QPushButton()
- self.center_button.setText(str(self.count))
- self.center_button.setFixedSize(25,25)
- self.btns.append(self.center_button)
- self.connect(self.center_button,SIGNAL("clicked()"),signal_mapper,SLOT("map()"))
- signal_mapper.setMapping(self.center_button, str(self.count))
- self.center_layout.addWidget(self.center_button)
- self.connect(signal_mapper, SIGNAL("mapped(QString)"), self, SLOT("showpage(QString)"))
- #print self.count
- @pyqtSlot(QString)
- def showpage(self,page):
- print page
- if __name__=='__main__':
- import sys
- app=QApplication(sys.argv)
- page=PageWidget()
- page.show()
- sys.exit(app.exec_())
效果图:
来源: http://www.phperz.com/article/17/1031/351811.html