网页制作免费网站,如何对网站进行维护,网站地图咋做,做游戏网站主页的素材分页控件效果图一、环境要求python解释器#xff1a;python3.7.4依赖#xff1a;PyQt5、sys模块二、思路分析1、布局#xff1a;”上一页“、”下一页“等button、edit及label控件采用水平布局#xff0c;使用该布局填充主控件QWidget2、类继承关系#xff1a;主界面继承自…分页控件效果图一、环境要求python解释器python3.7.4依赖PyQt5、sys模块二、思路分析1、布局”上一页“、”下一页“等button、edit及label控件采用水平布局使用该布局填充主控件QWidget2、类继承关系主界面继承自QWidget然后把button、edit、label等控件作为成员变量实现自定义的Widget3、类接口分析自定义的控件提供属性接口方便多种类对象之间的交互三、代码实现步骤1、定义一个新的控件继承自QWidget2、新控件界面的实现使用QHBoxLayout容器依次添加效果图所示的控件(也就是QPushButton、QLabel、QLineEdit等)并设置这些控件的文本属性3、校验为当前页数总过页数及跳转页数添加校验(永远不要相信用户的输入)当前页数至少为1且不能大于总的页数跳转的页数只能在1到总的页数之间且输入框只能输入整数4、添加事件响应四、代码展示from PyQt5.QtWidgets import (QWidget,QHBoxLayout,QPushButton,QLabel,QLineEdit,QApplication)from PyQt5.Qt import QIntValidatorimport sys1、提供数据翻页显示接口class PageController(QWidget):def __init__(self):super().__init__()self._init_ui()def _init_ui(self):control_layout QHBoxLayout()self.prePage QPushButton(self.curPage QLabel(1)self.nextPage QPushButton(下一页)self.totalPage QLabel(共 str(10) 页)skipLable_0 QLabel(跳到)self.skipPage QLineEdit()self.skipPage.setPlaceholderText(请输入跳转的页码)self.skipPage.setValidator(QIntValidator()) # 设置只能输入int类型的数据skipLabel_1 QLabel(页)self.confirmSkip QPushButton(确定)control_layout.addStretch(1)control_layout.addWidget(self.prePage)control_layout.addWidget(self.curPage)control_layout.addWidget(self.nextPage)control_layout.addWidget(self.totalPage)control_layout.addWidget(skipLable_0)control_layout.addWidget(self.skipPage)control_layout.addWidget(skipLabel_1)control_layout.addWidget(self.confirmSkip)control_layout.addStretch(1)self.setLayout(control_layout)self.setWindowTitle(分页控件demo)self.prePage.clicked.connect(self.button_clicked)self.nextPage.clicked.connect(self.button_clicked)self.confirmSkip.clicked.connect(self.button_clicked)def button_clicked(self):button_textself.sender().text()total_pageint(self.totalPage.text().split()[1])current_pageint(self.curPage.text())if self.skipPage.setText()current_pagecurrent_page-1if current_page1:self.curPage.setText(1)else:self.curPage.setText(str(current_page))if 下一页button_text:self.skipPage.setText()current_pagecurrent_page1if current_pagetotal_page:self.curPage.setText(str(current_page))if 确定button_text:if self.skipPage.text():returnpageint(self.skipPage.text())if 1pagetotal_page:self.curPage.setText(str(page))if pagetotal_page:self.curPage.setText(str(total_page))self.skipPage.setText(str(total_page))if page0:self.curPage.setText(str(1))self.skipPage.setText(str(1))propertydef PAGE(self):return int(self.totalPage.text().split()[1])PAGE.setterdef PAGE(self,page:int):if page0:returnself.totalPage.setText(共 str(page) 页)if __name____main__:appQApplication(sys.argv)winPageController()win.show()sys.exit(app.exec_())