python实现分页效果
作者:飞奔的猫 时间:2021-07-12 16:00:44
本文实例为大家分享了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://blog.csdn.net/jylonger/article/details/45767237
标签:python,分页
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
banner字体设计与应用
2009-07-06 14:42:00
![](https://img.aspxhome.com/file/UploadPic/20097/6/01-44s.jpg)
PHP中的Trait 特性及作用
2023-11-21 08:04:15
Python数据分析之双色球基于线性回归算法预测下期中奖结果示例
2021-12-04 12:39:55
![](https://img.aspxhome.com/file/2023/8/69578_0s.jpg)
不得不承认:韩国的 Web 设计很唯美
2009-05-13 13:26:00
![](https://img.aspxhome.com/file/UploadPic/20095/13/1221540-46s.jpg)
SQL Server修改标识列方法 如自增列的批量化修改
2012-06-06 19:42:35
960px下的黄金分割
2009-07-31 14:33:00
![](https://img.aspxhome.com/file/UploadPic/20097/31/498022_1248973274hhmt-19s.jpg)
开发心得--写给想学Javascript朋友的一点经验之谈
2009-02-25 11:42:00
也谈javascript程序优化问题
2008-10-29 11:30:00
讲解SQL Server数据库触发器的安全隐患
2009-02-24 17:46:00
SQL Server上进行表设计时表的主键设计问题
2010-06-24 16:10:00
动网论坛的asp 数据库连接代码
2011-04-06 10:32:00
通过XSL转换XML文件步骤
2008-01-27 16:03:00
一个CSS图片切换效果代码
2008-02-12 12:17:00
![](https://img.aspxhome.com/file/UploadPic/20082/12/2008212122716396s.jpg)
php时间不正确的解决方法
2023-11-18 07:33:15
禁止背景图在网页中平铺
2011-04-29 14:10:00
![](https://img.aspxhome.com/file/UploadPic/20072/2007231139890s.gif)
Python选课系统开发程序
2023-07-21 00:25:03
![](https://img.aspxhome.com/file/2023/3/70693_0s.png)
详解Python中的数据清洗工具flashtext
2021-10-05 01:59:47
![](https://img.aspxhome.com/file/2023/5/69645_0s.png)
php实现xml与json之间的相互转换功能实例
2023-11-22 05:38:00
js实现浏览器倒计时跳转页面效果
2023-07-18 06:49:57
![](https://img.aspxhome.com/file/2023/5/55915_0s.jpg)
javascript动态添加单元格的脚本代码
2023-09-02 05:21:26