【python】用python写一个小工具(懒人专用)

开发环境:

python-3.7.8rc1-amd64

Spyder

库:

一.实际应用

  1. 用QT绘制一个UI界面

以上应用都是本人平时用的比较多的,可根据自己所需来添加功能。

附源码:


from PyQt5 import QtCore, QtGui, QtWidgets


class Ui_MainWindow(object):
    def setupUi(self, MainWindow):
        MainWindow.setObjectName("MainWindow")
        MainWindow.resize(512, 436)
        self.centralwidget = QtWidgets.QWidget(MainWindow)
        self.centralwidget.setObjectName("centralwidget")
        self.label_22 = QtWidgets.QLabel(self.centralwidget)
        self.label_22.setGeometry(QtCore.QRect(-10, 0, 521, 391))
        self.label_22.setStyleSheet("border-image: url(:/BACK/109...jpg);")
        self.label_22.setText("")
        self.label_22.setObjectName("label_22")
        self.pushButton_5 = QtWidgets.QPushButton(self.centralwidget)
        self.pushButton_5.setGeometry(QtCore.QRect(150, 220, 75, 23))
        self.pushButton_5.setObjectName("pushButton_5")
        self.pushButton_14 = QtWidgets.QPushButton(self.centralwidget)
        self.pushButton_14.setGeometry(QtCore.QRect(420, 20, 75, 23))
        self.pushButton_14.setObjectName("pushButton_14")
        self.label_28 = QtWidgets.QLabel(self.centralwidget)
        self.label_28.setGeometry(QtCore.QRect(290, 120, 111, 21))
        self.label_28.setObjectName("label_28")
        self.pushButton_13 = QtWidgets.QPushButton(self.centralwidget)
        self.pushButton_13.setGeometry(QtCore.QRect(420, 170, 75, 23))
        self.pushButton_13.setObjectName("pushButton_13")
        self.label_18 = QtWidgets.QLabel(self.centralwidget)
        self.label_18.setGeometry(QtCore.QRect(20, 70, 111, 21))
        self.label_18.setObjectName("label_18")
        self.label_21 = QtWidgets.QLabel(self.centralwidget)
        self.label_21.setGeometry(QtCore.QRect(20, 220, 111, 21))
        self.label_21.setObjectName("label_21")
        self.pushButton_2 = QtWidgets.QPushButton(self.centralwidget)
        self.pushButton_2.setGeometry(QtCore.QRect(150, 70, 75, 23))
        self.pushButton_2.setObjectName("pushButton_2")
        self.pushButton_11 = QtWidgets.QPushButton(self.centralwidget)
        self.pushButton_11.setGeometry(QtCore.QRect(420, 220, 75, 23))
        self.pushButton_11.setObjectName("pushButton_11")
        self.pushButton = QtWidgets.QPushButton(self.centralwidget)
        self.pushButton.setGeometry(QtCore.QRect(150, 20, 75, 23))
        self.pushButton.setObjectName("pushButton")
        self.label_19 = QtWidgets.QLabel(self.centralwidget)
        self.label_19.setGeometry(QtCore.QRect(20, 120, 111, 21))
        self.label_19.setObjectName("label_19")
        self.pushButton_4 = QtWidgets.QPushButton(self.centralwidget)
        self.pushButton_4.setGeometry(QtCore.QRect(150, 170, 75, 23))
        self.pushButton_4.setObjectName("pushButton_4")
        self.pushButton_12 = QtWidgets.QPushButton(self.centralwidget)
        self.pushButton_12.setGeometry(QtCore.QRect(420, 70, 75, 23))
        self.pushButton_12.setObjectName("pushButton_12")
        self.label_29 = QtWidgets.QLabel(self.centralwidget)
        self.label_29.setGeometry(QtCore.QRect(290, 170, 111, 21))
        self.label_29.setObjectName("label_29")
        self.label_31 = QtWidgets.QLabel(self.centralwidget)
        self.label_31.setGeometry(QtCore.QRect(290, 220, 111, 21))
        self.label_31.setObjectName("label_31")
        self.label_30 = QtWidgets.QLabel(self.centralwidget)
        self.label_30.setGeometry(QtCore.QRect(290, 70, 111, 21))
        self.label_30.setObjectName("label_30")
        self.pushButton_3 = QtWidgets.QPushButton(self.centralwidget)
        self.pushButton_3.setGeometry(QtCore.QRect(150, 120, 75, 23))
        self.pushButton_3.setObjectName("pushButton_3")
        self.label_17 = QtWidgets.QLabel(self.centralwidget)
        self.label_17.setGeometry(QtCore.QRect(20, 20, 101, 21))
        self.label_17.setObjectName("label_17")
        self.label_20 = QtWidgets.QLabel(self.centralwidget)
        self.label_20.setGeometry(QtCore.QRect(20, 170, 111, 21))
        self.label_20.setObjectName("label_20")
        self.pushButton_15 = QtWidgets.QPushButton(self.centralwidget)
        self.pushButton_15.setGeometry(QtCore.QRect(420, 120, 75, 23))
        self.pushButton_15.setObjectName("pushButton_15")
        self.label_27 = QtWidgets.QLabel(self.centralwidget)
        self.label_27.setGeometry(QtCore.QRect(290, 20, 111, 21))
        self.label_27.setObjectName("label_27")
        self.label = QtWidgets.QLabel(self.centralwidget)
        self.label.setGeometry(QtCore.QRect(20, 340, 71, 51))
        self.label.setObjectName("label")
        self.lineEdit = QtWidgets.QLineEdit(self.centralwidget)
        self.lineEdit.setGeometry(QtCore.QRect(70, 350, 151, 31))
        self.lineEdit.setObjectName("lineEdit")
        self.label_2 = QtWidgets.QLabel(self.centralwidget)
        self.label_2.setGeometry(QtCore.QRect(290, 340, 71, 51))
        self.label_2.setObjectName("label_2")
        self.lineEdit_2 = QtWidgets.QLineEdit(self.centralwidget)
        self.lineEdit_2.setGeometry(QtCore.QRect(340, 350, 161, 31))
        self.lineEdit_2.setObjectName("lineEdit_2")
        self.label_23 = QtWidgets.QLabel(self.centralwidget)
        self.label_23.setGeometry(QtCore.QRect(20, 270, 111, 21))
        self.label_23.setObjectName("label_23")
        self.pushButton_6 = QtWidgets.QPushButton(self.centralwidget)
        self.pushButton_6.setGeometry(QtCore.QRect(150, 270, 75, 23))
        self.pushButton_6.setObjectName("pushButton_6")
        self.label_24 = QtWidgets.QLabel(self.centralwidget)
        self.label_24.setGeometry(QtCore.QRect(290, 270, 111, 21))
        self.label_24.setObjectName("label_24")
        self.pushButton_7 = QtWidgets.QPushButton(self.centralwidget)
        self.pushButton_7.setGeometry(QtCore.QRect(420, 270, 75, 23))
        self.pushButton_7.setObjectName("pushButton_7")
        self.pushButton_8 = QtWidgets.QPushButton(self.centralwidget)
        self.pushButton_8.setGeometry(QtCore.QRect(230, 350, 51, 31))
        self.pushButton_8.setObjectName("pushButton_8")
        MainWindow.setCentralWidget(self.centralwidget)
        self.menubar = QtWidgets.QMenuBar(MainWindow)
        self.menubar.setGeometry(QtCore.QRect(0, 0, 512, 23))
        self.menubar.setObjectName("menubar")
        MainWindow.setMenuBar(self.menubar)
        self.statusbar = QtWidgets.QStatusBar(MainWindow)
        self.statusbar.setObjectName("statusbar")
        MainWindow.setStatusBar(self.statusbar)


        self.retranslateUi(MainWindow)
        QtCore.QMetaObject.connectSlotsByName(MainWindow)

    def retranslateUi(self, MainWindow):
        _translate = QtCore.QCoreApplication.translate
        MainWindow.setWindowTitle(_translate("MainWindow", "PPN"))
        self.pushButton_5.setText(_translate("MainWindow", "运行"))
        self.pushButton_14.setText(_translate("MainWindow", "运行"))
        self.label_28.setText(_translate("MainWindow", "打开电脑适配器:"))
        self.pushButton_13.setText(_translate("MainWindow", "运行"))
        self.label_18.setText(_translate("MainWindow", "打开NBA东西部排名:"))
        self.label_21.setText(_translate("MainWindow", "小游戏:"))
        self.pushButton_2.setText(_translate("MainWindow", "运行"))
        self.pushButton_11.setText(_translate("MainWindow", "运行"))
        self.pushButton.setText(_translate("MainWindow", "运行"))
        self.label_19.setText(_translate("MainWindow", "打开CSDN学习:"))
        self.pushButton_4.setText(_translate("MainWindow", "运行"))
        self.pushButton_12.setText(_translate("MainWindow", "运行"))
        self.label_29.setText(_translate("MainWindow", "打开设备管理器:"))
        self.label_31.setText(_translate("MainWindow", "打开Mysql数据库:"))
        self.label_30.setText(_translate("MainWindow", "打开CSDN我的内容:"))
        self.pushButton_3.setText(_translate("MainWindow", "运行"))
        self.label_17.setText(_translate("MainWindow", "打开NBA图文数据:"))
        self.label_20.setText(_translate("MainWindow", "打开翻译:"))
        self.pushButton_15.setText(_translate("MainWindow", "运行"))
        self.label_27.setText(_translate("MainWindow", "打开图片转换工具:"))
        self.label.setText(_translate("MainWindow", "搜索:"))
        self.label_2.setText(_translate("MainWindow", "返回:"))
        self.label_23.setText(_translate("MainWindow", "打开计算器:"))
        self.pushButton_6.setText(_translate("MainWindow", "运行"))
        self.label_24.setText(_translate("MainWindow", "打开记事本:"))
        self.pushButton_7.setText(_translate("MainWindow", "运行"))
        self.pushButton_8.setText(_translate("MainWindow", "run"))
import TUTU_rc

  1. 实现第一个小功能(打开NBA每日图文数据页面)


from selenium import webdriver  ###导入selenium库

def nbat():
    driver = webdriver.Chrome()####实例化浏览器
    option = webdriver.ChromeOptions()
    option.add_experimental_option("detach", True)
    driver = webdriver.Chrome(executable_path='C:/Users/86180/.spyder-py3/chromedriver.exe', options=option)

    ###写入NBA图文数据的网址
    driver.get('https://www.baidu.com/s?ie=utf-8&f=8&rsv_bp=1&tn=baidu&wd=nba&oq=python&rsv_pq=c18baa0e00004f4f&rsv_t=9655EB0Ke9Xsp6M3b%2BNToueiabZBl8ljQrRtdyJjHiJMB3h%2Bop6ZTZ%2FYLvU&rqlang=cn&rsv_enter=1&rsv_dl=tb&rsv_sug3=7&rsv_sug1=7&rsv_sug7=100&rsv_sug2=0&rsv_btype=t&inputT=627&rsv_sug4=2425')###进入此网址
        
    ###页面最大化显示
    driver.maximize_window()

输出:

小工具的代码有类似,这边就举几个不同的例子

2.实现第二个小功能(打开记事本)


import os##导入os库

def jb():
    os.system("notepad.exe") ###os库里面的system函数直接打开记事本

输出:

超简单的功能实现

  1. 实现第三个小功能(打开小游戏)

输出:

是一个飞机大战的游戏,有时间可以出一期pygame的教程

  1. 小型搜索(百度)

输入想搜索的内容,点击run,成功后返回框内会打印数值

例:

直接输入要搜索的内容,run

,哈哈哈哈哈挺有趣的一个小功能,其实就是百度搜索。

自己动手试一下吧。

想获取源码的小伙伴,点击下方关注下我的微信公众号,后台私信我奥!

公众号不定期也会更新一些有意思的小项目及教程等~

@Neng

评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Penley.

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值