python实现分页效果

 更新时间:2017年10月25日 17:20:53   作者:飞奔的猫  
这篇文章主要为大家详细介绍了python实现分页效果,具有一定的参考价值,感兴趣的小伙伴们可以参考一下

本文实例为大家分享了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_()) 

 效果图:

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持脚本之家。

相关文章

  • Python使用matplotlib显示图像实例

    Python使用matplotlib显示图像实例

    在Python项目中处理图像数据之前,需要确保安装了matplotlib库,它是一个用于绘制图表和图像显示的工具,若尚未安装,可以使用pip命令进行安装,安装完成后,可以通过matplotlib的pyplot模块读取并显示MNIST手写数据集中的图像,若需要显示灰度图
    2024-10-10
  • Python 12306抢火车票脚本

    Python 12306抢火车票脚本

    这篇文章主要为大家详细介绍了Python 12306抢火车票脚本,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
    2018-02-02
  • 在python3环境下的Django中使用MySQL数据库的实例

    在python3环境下的Django中使用MySQL数据库的实例

    下面小编就为大家带来一篇在python3环境下的Django中使用MySQL数据库的实例。小编觉得挺不错的,现在就分享给大家,也给大家做个参考。一起跟随小编过来看看吧
    2017-08-08
  • python输出国际象棋棋盘的实例分享

    python输出国际象棋棋盘的实例分享

    在本篇文章里小编给大家整理的是一篇关于python输出国际象棋棋盘的实例详解,有兴趣的朋友们可以参考下。
    2020-11-11
  • pycharm激活码2020最新分享适用pycharm2020最新版亲测可用

    pycharm激活码2020最新分享适用pycharm2020最新版亲测可用

    这篇文章主要介绍了pycharm激活码2020最新分享适用pycharm2020最新版亲测可用,同时也支持Intellij IDEA激活码,PHPStorm激活码大家可以放心使用需要的朋友可以参考下
    2020-11-11
  • SQLite3中文编码 Python的实现

    SQLite3中文编码 Python的实现

    下面小编就为大家带来一篇SQLite3中文编码 Python的实现。小编觉得挺不错的,现在就分享给大家,也给大家做个参考。一起跟随小编过来看看吧
    2017-01-01
  • python基于scrapy爬取京东笔记本电脑数据并进行简单处理和分析

    python基于scrapy爬取京东笔记本电脑数据并进行简单处理和分析

    这篇文章主要介绍了python基于scrapy爬取京东笔记本电脑数据并进行简单处理和分析的实例,帮助大家更好的理解和学习使用python。感兴趣的朋友可以了解下
    2021-04-04
  • pytorch:torch.mm()和torch.matmul()的使用

    pytorch:torch.mm()和torch.matmul()的使用

    今天小编就为大家分享一篇pytorch:torch.mm()和torch.matmul()的使用,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧
    2019-12-12
  • Django中多种重定向方法使用详解

    Django中多种重定向方法使用详解

    这篇文章主要介绍了Django中多种重定向方法使用详解,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下
    2019-07-07
  • TensorFlow中如何确定张量的形状实例

    TensorFlow中如何确定张量的形状实例

    这篇文章主要介绍了TensorFlow中如何确定张量的形状实例,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧
    2020-06-06

最新评论