一、制作基于windows系统批量重命名文件小工具

参考博客:

使用python做一个批量重命名文件的小工具_讷言丶的博客-CSDN博客

效果展示:

临时01

代码实现:

import os
from tkinter import filedialog
import tkinter as tk
from tkinter import messageboxroot = tk.Tk()
root.geometry('400x200+550+200')
root.title('批量重命名文件小工具')
page = tk.Frame()
page.pack()
text = tk.StringVar()def rename_file():filepath = filedialog.askdirectory()index = 0if len(os.listdir(filepath)) == 0:messagebox.showinfo(title="文件重命名", message="该目录下文件为空,请重新选择目录")else:for filename in os.listdir(filepath):index += 1file_path = os.path.join(filepath, filename)if os.path.isfile(file_path):name, ext = os.path.splitext(filename)new_name = text.get() + str(index) + ext# print(new_name)os.rename(file_path, os.path.join(filepath, new_name))messagebox.showinfo(title='文件重命名', message='文件重命名成功,请查看目录')tk.Label(page).grid(row=0, column=1)
tk.Label(page, text='文件名称前缀:', font=('华文楷体', 15)).grid(row=2, column=1, pady=10)
tk.Entry(page, textvariable=text).grid(row=2, column=2)
tk.Button(page, text='选择目录并重命名文件', font=('华文楷体', 15), command=rename_file).grid(row=3, column=2)
root.mainloop()

二、制作时间戳转换器

效果展示:

临时03

代码实现:

import time
import tkinter as tk
from tkinter import messageboxroot = tk.Tk()
root.geometry('400x300+500+300')
root.title('时间戳转换工具')usertime = tk.StringVar()
usertimestamp = tk.StringVar()page = tk.Frame(root)
page.pack()tk.Label(page).grid(row=0, column=1)tk.Label(page, text='请输入时间【格式:Y-M-D h:m:s】:', font=('黑体', 10)).grid(row=1, column=1, pady=10)
tk.Entry(page, textvariable=usertime).grid(row=1, column=2)tk.Label(page, text='请输入时间戳: ', font=('黑体', 10)).grid(row=3, column=1, pady=30)
tk.Entry(page, textvariable=usertimestamp).grid(row=3, column=2)# 将时间转换为时间戳,秒级
def timestamp_s():time_value = usertime.get()timeArray = time.strptime(time_value, "%Y-%m-%d %H:%M:%S")timestamp = time.mktime(timeArray)times = int(timestamp)messagebox.showinfo(title='时间戳(s)', message=f'获取到的时间戳(s)为{times}')# 将时间转换为时间戳,毫秒级
def timestamp_ms():time_value = usertime.get()timeArray = time.strptime(time_value, "%Y-%m-%d %H:%M:%S")timestamp = time.mktime(timeArray)times = int(round(timestamp * 1000))messagebox.showinfo(title='时间戳(s)', message=f'获取到的时间戳(s)为{times}')# 秒级时间戳转换
def time_s():time_value = usertimestamp.get()if len(time_value) == 10:timeas = int(time_value)time_local = time.localtime(timeas)dt = time.strftime("%Y-%m-%d %H:%M:%S", time_local)messagebox.showinfo(title='时间', message=f'获取到的时间为{dt}')elif len(time_value) == 13:timeas = int(time_value)timestamps = int(round(timeas / 1000))time_local = time.localtime(timestamps)dt = time.strftime("%Y-%m-%d %H:%M:%S", time_local)messagebox.showinfo(title='时间', message=f'获取到的时间为{dt}')tk.Button(page, text='转换为时间戳(s)', command=timestamp_s).grid(row=2, column=1)
tk.Button(page, text='转换为时间戳(ms)', command=timestamp_ms).grid(row=2, column=2)
tk.Button(page, text='转换为时间', command=time_s).grid(row=4, column=1)
root.mainloop()

三、制作图书管理小工具

效果展示:

临时02

代码实现:

import tkinter as tk
from tkinter import messagebox# 定义Book类
class Book:def __init__(self, title, author, isbn):self.title = titleself.author = authorself.isbn = isbn# 定义GUI窗口
class BookManagementSystem:def __init__(self, master):self.master = masterself.master.title("图书管理系统")# 创建标题标签tk.Label(self.master, text="图书管理系统", font=("Arial", 20)).grid(column=0, row=0, columnspan=3, pady=10)# 创建书籍信息输入框tk.Label(self.master, text="书名").grid(column=0, row=1)self.title_entry = tk.Entry(self.master)self.title_entry.grid(column=1, row=1, padx=5, pady=5)tk.Label(self.master, text="作者").grid(column=0, row=2)self.author_entry = tk.Entry(self.master)self.author_entry.grid(column=1, row=2, padx=5, pady=5)tk.Label(self.master, text="ISBN号").grid(column=0, row=3)self.isbn_entry = tk.Entry(self.master)self.isbn_entry.grid(column=1, row=3, padx=5, pady=5)# 创建添加书籍按钮self.add_book_button = tk.Button(self.master, text="添加书籍", command=self.add_book)self.add_book_button.grid(column=0, row=4, pady=10)# 创建书籍列表框tk.Label(self.master, text="当前书籍列表").grid(column=2, row=1)self.book_listbox = tk.Listbox(self.master)self.book_listbox.grid(column=2, row=2, rowspan=3, padx=10, pady=5)self.update_book_list()# 创建删除书籍按钮self.delete_book_button = tk.Button(self.master, text="删除书籍", command=self.delete_book)self.delete_book_button.grid(column=2, row=4, pady=10)# 添加书籍方法def add_book(self):title = self.title_entry.get()author = self.author_entry.get()isbn = self.isbn_entry.get()book = Book(title, author, isbn)with open("books.txt", "a") as f:f.write(f"{book.title},{book.author},{book.isbn}\n")messagebox.showinfo("添加书籍", "添加书籍成功!")self.update_book_list()# 删除书籍方法def delete_book(self):selection = self.book_listbox.curselection()if len(selection) == 0:messagebox.showerror("删除书籍", "请选择要删除的书籍!")returnindex = selection[0]book = self.book_listbox.get(index)with open("books.txt", "r") as f:lines = f.readlines()with open("books.txt", "w") as f:for line in lines:if line.strip() != book:f.write(line)messagebox.showinfo("删除书籍", "删除书籍成功!")self.update_book_list()# 更新书籍列表方法def update_book_list(self):self.book_listbox.delete(0, tk.END)with open("books.txt", "r") as f:for line in f.readlines():book = line.strip()self.book_listbox.insert(tk.END, book)# 启动GUI窗口
if __name__ == '__main__':root = tk.Tk()app = BookManagementSystem(root)root.mainloop()

四、制作jpg、png图片转ico图标小工具

效果展示:

临时04

代码实现:

import tkinter as tk
from tkinter import filedialog
# PythonMargick包可以到Unofficial Windows Binaries for Python Extension Packages下载
import PythonMagickroot = tk.Tk()
root.withdraw()Fpath = filedialog.askopenfilename()img = PythonMagick.Image(Fpath)
# 这里要设置一下尺寸,不然会报ico尺寸异常错误
img.sample('256x256')
img.write('robin.ico')

五、制作图片和base64互转小工具

效果展示:

临时05

代码实现:

import base64
import tkinter as tk
from tkinter import filedialogroot = tk.Tk()
root.withdraw()Fpath = filedialog.askopenfilename()
def file_to_base64():print(Fpath)f=open(Fpath,'rb') #二进制方式打开图文件ls_f=base64.b64encode(f.read()) #读取文件内容,转换为base64编码open('x.txt', 'wb').write(ls_f)def base64_to_file():print(Fpath)decoded = base64.b64decode(open(Fpath, 'rb').read())open('1.jpg', 'wb').write(decoded)  # 保存if __name__ == '__main__':if "jpg" in Fpath or 'png' in Fpath or 'jpeg' in Fpath:file_to_base64()elif 'txt' in Fpath:base64_to_file()

六、制作英文翻译器(小工具)

代码逻辑:

requests模块请求第三方翻译接口,拿到数据后通过tkinter展示出来

效果展示:

临时06

代码实现:

import requests
import tkinter as tk
from tkinter import messageboxroot = tk.Tk()
root.geometry('1000x500+350+100')
root.title('英文翻译器')
page = tk.Frame()
page.pack()text = tk.StringVar()
tk.Label(page).grid(row=0, column=1)
tk.Label(page, text='翻译小程序', font=('黑体', 20)).grid(row=1, column=1, pady=20)def sure():page.pack_forget()page2.pack()def exit():page2.pack_forget()page.pack()def dcfy():url = 'https://fanyi.xxx.com/trans'headers = {"user-agent": 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/111.0.0.0 Safari/537.36',"referer": 'https://fanyi.xxx.com/'}chinese = text.get()data = {'q': chinese,'from': 'Auto','to': 'Auto'}resp = requests.post(url=url, headers=headers, data=data).json()chinatext = resp.get('web')[0]['key']Englishtext = resp.get('web')[0]['value'][0]messagebox.showinfo(title='单词翻译', message=Englishtext)def para():page.pack_forget()page3.pack()def exit2():page3.pack_forget()page.pack()def dlfy():url = 'https://fanyi.xxx.com/trans'headers = {"user-agent": 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/111.0.0.0 Safari/537.36',"referer": 'https://fanyi.xxx.com/'}chinese = text.get()data = {'q': chinese,'from': 'Auto','to': 'Auto'}resp = requests.post(url=url, headers=headers, data=data).json()Englishtext = resp['translation'][0]messagebox.showinfo(title='段落句子翻译', message=f'{Englishtext}')tk.Button(page, text='单词翻译', font=('黑体', 15), command=sure).grid(row=2, column=1, pady=20)
tk.Button(page, text='句子翻译', font=('黑体', 15), command=para).grid(row=2, column=2, padx=10, pady=20)page2 = tk.Frame()
tk.Entry(page2, textvariable=text, bd=5).grid(row=2, column=2, pady=20)
tk.Button(page2, text='翻译', font=('黑体', 15), command=dcfy).grid(row=3, column=1, padx=20)
tk.Button(page2, text='返回上一页', font=('黑体', 15), command=exit).grid(row=3, column=2, pady=20)page3 = tk.Frame()
tk.Entry(page3, textvariable=text, bd=5).grid(row=2, column=2, pady=20)
tk.Button(page3, text='翻译', font=('黑体', 15), command=dlfy).grid(row=3, column=1, padx=20)
tk.Button(page3, text='返回上一页', font=('黑体', 15), command=exit2).grid(row=3, column=2, pady=20)root.mainloop()

七、制作图片查看器(小工具):

效果展示:

临时07

代码实现:

import tkinter as tk
import glob
from PIL import Image, ImageTkroot = tk.Tk()  # 创建窗口
root.geometry('650x700+300+50')  # 设置弹出窗口的大小和在屏幕中的位置
root.title('图片查看器')  # 设置弹出窗口的标题imgs = glob.glob('img/*.jpeg')
imgs = [ImageTk.PhotoImage(Image.open(item)) for item in imgs]current_photo_no = 0
img_label = tk.Label(root, image=imgs[current_photo_no], width=640, height=640)
img_label.pack()
number_var = tk.StringVar()
number_var.set('1 of 8')
tk.Label(root, textvariable=number_var, bd=1, relief=tk.SUNKEN, anchor=tk.CENTER).pack(fill=tk.X)button_form = tk.Frame(root)
button_form.pack()
prev_img = tk.Button(button_form, text='上一页')
next_img = tk.Button(button_form, text='下一页')
prev_img.pack(side=tk.LEFT, anchor=tk.CENTER)
next_img.pack(side=tk.RIGHT, anchor=tk.CENTER)def change_images(next_no):global current_photo_nocurrent_photo_no += next_noif current_photo_no >= len(imgs):current_photo_no = 0if current_photo_no < 0:current_photo_no = len(imgs) - 1number_var.set(f'{current_photo_no + 1} of {len(imgs)}')img_label.configure(image=imgs[current_photo_no])prev_img.config(command=lambda: change_images(-1))
next_img.config(command=lambda: change_images(1))
root.mainloop()

八、制作BMI身体指数计算器(小工具):

效果展示:

临时08

代码实现:

import tkinter as tk
from tkinter import messageboxroot = tk.Tk()
root.geometry('350x230+500+230')  # 设置弹出框位置和大小
# root.iconbitmap('E:/pythonProject/3.ico')  # 设置弹出框图标root.title('BMI身体指数计算器')height = tk.DoubleVar()
weight = tk.DoubleVar()page = tk.Frame(root)
page.pack()tk.Label(page).grid(row=0, column=0)tk.Label(page, text='身高(米): ').grid(row=2, column=1, pady=20)
tk.Entry(page, textvariable=height).grid(row=2, column=2)tk.Label(page, text='体重(kg): ').grid(row=3, column=1, pady=20)
tk.Entry(page, textvariable=weight).grid(row=3, column=2)def jisuan():shengao = height.get()tizhong = weight.get()# print(shengao,tizhong)if shengao > 0 and tizhong > 0:BMI = tizhong / shengao ** 2BMI_new = float(('%.2f' % BMI))messagebox.showinfo(title='BMI身体指数计算',message=f'您的身高为{shengao}m,您的体重为{tizhong}kg,您的BMI身体指数为{BMI_new}')if BMI_new < 18.4:messagebox.showinfo(title='BMI身体指数计算', message='BMI指数较低,提示您的身体消瘦,要注意补充营养哦!')elif BMI_new > 18.5 and BMI_new < 24:messagebox.showinfo(title='BMI身体指数计算', message='BMI指数为正常值,继续加油!')elif BMI_new > 24 and BMI_new < 28:messagebox.showinfo(title='BMI身体指数计算',message='BMI指数较高,属于是超重了,提示您需要合理饮食,加强锻炼哦!')elif BMI_new > 28:messagebox.showinfo(title='BMI身体指数计算',message='BMI指数很高,属于肥胖了,提示您需要注意身体健康了,过胖会增加人体器官的负担哦!')tk.Button(page, text='计算', command=jisuan).grid(row=4, column=2, pady=10)root.mainloop()

九,制作OCR图片识别小工具

参考博客:

【Python • 图片识别】pytesseract快速识别提取图片中的文字_python识别图片中的文字_广龙宇的博客-CSDN博客利用python做图片识别,识别提取图片中的文字会有很多方法,但是想要简单一点怎么办,那就可以使用tesseract识别引擎来实现,一行代码就可以做到提取图片文本。_python识别图片中的文字https://blog.csdn.net/weixin_47754149/article/details/125651707

效果展示:

临时09

代码实现:

from PIL import Image
import pytesseract
import tkinter as tk
from tkinter import filedialogroot = tk.Tk()
root.withdraw()Fpath = filedialog.askopenfilename()def read_image(name):with open('视频文件.txt','w',encoding='utf-8') as fp:fp.write(pytesseract.image_to_string(Image.open(name), lang='chi_sim'))def main():read_image(Fpath)if __name__ == '__main__':reslet = main()

python入门学习小工具制作系列各种小工具整理相关推荐

  1. 用python画哆啦a梦的身体_每天一个Python小技巧,用Python 画个多啦A梦,小猪佩奇,文末还有Python入门学习视频...

    见网络上有人用Python 画出来个多啦A梦,很是新奇,来来来,我们看一下他们主要用到的库. 其实主要用的库就一个 turtle 库 先说明一下turtle绘图的基础知识: 1. 画布(canvas) ...

  2. python turtle绕原点旋转_每天一个Python小技巧,用Python 画个多啦A梦,小猪佩奇,文末还有Python入门学习视频

    见网络上有人用Python 画出来个多啦A梦,很是新奇,来来来,我们看一下他们主要用到的库. 其实主要用的库就一个 turtle 库 先说明一下turtle绘图的基础知识: 1. 画布(canvas) ...

  3. python入门视频教程推荐-python入门学习哪个书比较好(python视频教程知乎)

    自学python的学习路线是什么?推荐一些python学习资源 第一段 初级,掌握Python的语法和常用库的使用 这里首先推雪锋在网上的书籍,这是Python2.7的,这本书适合于重头开始一直读完, ...

  4. Python入门学习指南--内附学习框架

    Python入门学习指南 原文链接:https://blog.csdn.net/weixin_44558127/article/details/86527360 最近开始整理python的资料,博主建 ...

  5. 自学python买什么书比较好-python入门学习哪个书比较好(python视频教程知乎)

    自学python的学习路线是什么?推荐一些python学习资源 第一段 初级,掌握Python的语法和常用库的使用 这里首先推雪锋在网上的书籍,这是Python2.7的,这本书适合于重头开始一直读完, ...

  6. python速成要多久2019-8-28_2019最全Python入门学习路线,不是我吹,绝对是最全

    近几年Python的受欢迎程度可谓是扶摇直上,当然了学习的人也是愈来愈多.一些学习Python的小白在学习初期,总希望能够得到一份Python学习路线图,小编经过多方汇总为大家汇总了一份Python学 ...

  7. 自学python推荐书籍2019-2019最全Python入门学习路线,不是我吹,绝对是最全

    近几年Python的受欢迎程度可谓是扶摇直上,当然了学习的人也是愈来愈多.一些学习Python的小白在学习初期,总希望能够得到一份Python学习路线图,小编经过多方汇总为大家汇总了一份Python学 ...

  8. Python入门学习笔记1-Python基础

    Python入门学习笔记1-Python基础 前言:本文介绍了Python学习的前导知识概念以及必记基础函数,如善用help方法查看帮助文档,以及内置对象类型的概念以及常用函数的详解. 一.Pytho ...

  9. python从零开始到精通_「Python 入门学习指南」0基础小白助你从入门到精通!

    Python比较简单,非常适合初学者入门,内置了各种库,还有丰富的大约13万第三方库,掌握了语法和编程思维后,可以直接使用这些库做出自己的产品.这篇 Python 入门学习指南,针对没有任何编程经验. ...

最新文章

  1. C++中 何时用. 何时用-」
  2. [JS] 动态修改ckPlayer播放器宽度
  3. 【留用】C#的一些好的书籍
  4. 如何从零开始开发一个实时联机游戏?
  5. c语言程序设计教案 文库,C语言程序设计教案.doc
  6. 用sort()方法随机打乱数组
  7. docker 安装 FastDFS
  8. Failed to access IIS metabase
  9. 4、elasticsearch安装head插件
  10. android离线天地图,天地图的移动App开发,离线地图下载不了
  11. mx350显卡天梯图_不可错过的2020显卡天梯图,选卡详解
  12. 「To B端增长黑客」 获客矩阵
  13. QQ电脑版 快捷cmd指令
  14. web概念、B/C、C/S区别与优缺点以及网络通信三要素:IP、端口号、传输地址
  15. 完整正则表达式语法列表
  16. 移植quectel的GPS模块
  17. cprogram作业
  18. 【Android开发】Android休眠机制
  19. solr和lucene_使用Apache Lucene和Solr 4进行下一代搜索和分析
  20. 大内存加速网站应用方案

热门文章

  1. 10_结构体与共同体
  2. Android instrumented test no tests found
  3. 表单引擎功能研究分析
  4. .NET Compact Framework 移动开发步步来(3)
  5. CentOS 7安装教程(图文详解)
  6. thead java_Java中多线程的使用(超级超级详细) Thead类的使用 3
  7. Dogs vs. Cats数据集
  8. C语言库函数的实现(strlen strcpy strcmp strcat strstr)
  9. 再谈CPU使用率100%的问题
  10. 淡黄色阴离子交换树脂-CsPbBr3量子点/FA-PEG-DSPE-CdTe的制备