首页 > 编程语言 >python pyqt5简单界面

python pyqt5简单界面

时间:2023-02-01 12:02:04浏览次数:56  
标签:layout footer python text self pyqt5 addButton 界面 btn


​https://doc.qt.io/qtforpython/PySide6/QtWidgets/QTableWidget.html​

python pyqt5简单界面_开发语言

import sys
from PyQt5.QtWidgets import QApplication, QWidget, QDesktopWidget, QHBoxLayout, QVBoxLayout, QTableWidget, \
QTableWidgetItem
from PyQt5.QtWidgets import QPushButton, QLineEdit,QLabel


class MainWindow(QWidget):
def __init__(self):
super().__init__()

# 窗体标题和尺寸
self.setWindowTitle("NB的xx系统")

# 窗体的尺寸
self.resize(1228, 450)

# 窗体的位置
qr = self.frameGeometry()
cp = QDesktopWidget().availableGeometry().center()
qr.moveCenter(cp)

# 垂直方向的布局
layout = QVBoxLayout()

# 1.创建顶部菜单布局
header_layout = QHBoxLayout()
layout.addLayout(header_layout)
# 1.1 创建按钮
self.btn_start = self.addButton(header_layout, '开始')
self.btn_start = self.addButton(header_layout, '停止')
self.addStretch(header_layout)

# 2.创建上面标题布局
form_layout = QHBoxLayout()
layout.addLayout(form_layout)
# 2.1 输入框

self.txt_asin = self.addLineEdit(form_layout, "请输入商品ID和价格,列入:B0818JJQQ8=88")
# 2.2 添加按钮
self.btn_add = self.addButton(form_layout, '添加')

# 3.创建中间的表格
table_layout = QHBoxLayout()
layout.addLayout(table_layout)
# 3.1 创建表格
title_dict = [
{'field':'asin','text':'ASIN','width':120},
{'field':'title','text':'标题','width':150},
{'field':'url','text':'URL','width':400},
{'field':'price','text':'底价','width':100},
{'field':'success','text':'成功次数','width':100},
{'field':'error','text':'503次数','width':100},
{'field':'status','text':'状态','width':100},
{'field':'frequency','text':'频率(N秒/次)','width':100},
]
self.table_widget = self.addTable(layout,title_dict,8,0)


# 4.创建底部菜单
footer_layout = QHBoxLayout()
layout.addLayout(footer_layout)
self.label_status = self.addLabel(footer_layout,'未检测')
self.addStretch(footer_layout)
self.btn_reinit = self.addButton(footer_layout, '重新初始化')
self.btn_recheck = self.addButton(footer_layout, '重新检查')
self.btn_reset_count = self.addButton(footer_layout, '次数清零')
self.btn_delete = self.addButton(footer_layout, '删除检测项')
self.btn_alert = self.addButton(footer_layout, 'SMTP报警配置')
self.btn_proxy = self.addButton(footer_layout, '代理IP')
# 给窗体设置元素的排列方式
self.setLayout(layout)

def addButton(self, layout, button_name):
button = QPushButton(button_name)
layout.addWidget(button)
return button
def addLabel(self, layout, text):
label = QLabel(text)
layout.addWidget(label)
return label

def addStretch(self, layout):
layout.addStretch()

def addLineEdit(self, layout, place_holder_text):
line_edit = QLineEdit()
line_edit.setPlaceholderText(place_holder_text)
layout.addWidget(line_edit)
return line_edit

def addTable(self, layout, title_list, col, row):
table = QTableWidget(row, col)
for index, value in enumerate(title_list):
item = QTableWidgetItem()
item.setText(value['text'])
table.setColumnWidth(index,value['width'])
table.setHorizontalHeaderItem(index, item)
layout.addWidget(table)


if __name__ == '__main__':
app = QApplication(sys.argv)
window = MainWindow()
window.show()
sys.exit(app.exec_())


标签:layout,footer,python,text,self,pyqt5,addButton,界面,btn
From: https://blog.51cto.com/u_10780206/6031185

相关文章

  • python json to txt
    defread(self):file_path=os.path.join("db","alert.json")ifos.path.exists(file_path):file_object=open(file_path,mode='r',encodin......
  • python pyinstaller 打包方式介绍
    '''pipinstallpyinstaller单个pyinstaller-Fv3.py单个隐藏黑框pyinstaller-Fv3.py-w多个带很多文件pyinstaller-Dv3.py多个带很多文件隐藏黑框pyinstaller-Dv3......
  • pyqt5 简单工具类
    fromPyQt5.QtWidgetsimportQPushButton,QLabel,QLineEdit,QTextEdit,QPlainTextEdit,QCheckBoxfromPyQt5.QtWidgetsimportQComboBox,QRadioButtonclassMYWIDGET():......
  • pyqt5 简单模板
    importsysfromPyQt5.QtCoreimportQtfromPyQt5.QtWidgetsimportQWidget,QDesktopWidget,QVBoxLayout,QHBoxLayout,QApplication,QButtonGroupfromutils.tableUt......
  • Python经典题:找出1-9中有那些组合相加等于一个特定值,例如说20,一个列表中元素进行组合,
     找出1-9中有那些组合相加等于一个特定值,例如说20num=[1,2,3,4,5,6,7,8,9]defcount(num,n):#num=list(sorted(filter(lambdax:x<=n,num)))#pri......
  • python mongo查询
    importpymongo#连接数据库环境myclient1=pymongo.MongoClient('mongodb://账号:密码@ip:端口/')mydb1=myclient1["slot"]//dbmycol1=mydb1["ota.versions"]//表x=my......
  • python excel操作读取,写入
    importxlrd,xlwtfromxlutilsimportcopy#读取excel表格某个数据data=xlrd.open_workbook("select125.xls")tablerd=data.sheet_by_name("Sheet1")rowNum=tablerd......
  • 跟着廖雪峰学 python 002
    ​ ​编辑 #表示注释:表示缩进的语句是代码块(缩进一般是四个空格)数据类型整数:        在程序中的表示方法和数学上的写法一模一样(正整数和负整数) ......
  • 详解如何用 C 为 Python 实现扩展模块
    当Python代码的执行效率不高时,我们会选择将性能相关的部分交给C来实现,但这要求开发者必须熟悉Python提供的CAPI。为此我专门写了一个系列,介绍如何用C给Python......
  • Python发送邮件脚本
    目的:将Python执行脚本结果发送到指定邮箱 1、以下163邮箱为例,设置发件人是163邮箱,接收人是qq邮箱。由于163邮箱的安全机制,Python登陆163邮件客户端不是使用邮箱密码而......