欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Python實(shí)現(xiàn)圖片格式轉(zhuǎn)換小程序

 更新時(shí)間:2022年08月09日 17:20:28   作者:aguang5241  
這篇文章主要為大家詳細(xì)介紹了Python實(shí)現(xiàn)圖片格式轉(zhuǎn)換小程序,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

基于Python實(shí)現(xiàn)圖片格式轉(zhuǎn)換的小程序,供大家參考,具體內(nèi)容如下

特點(diǎn):

1.批量處理圖片
2.轉(zhuǎn)換常見(jiàn)的4種圖片格式

運(yùn)行窗口

運(yùn)行窗口-1

選擇圖片(可批量選擇)-2

假設(shè)選中4張JEPG格式的圖片

格式選擇窗口-3

假設(shè)選擇目標(biāo)格式PNG

結(jié)束窗口-4

結(jié)果展示-5

可以發(fā)現(xiàn)4個(gè)JEPG目標(biāo)圖片成功轉(zhuǎn)換為PNG格式的圖片

代碼

import tkinter as tk
import tkinter.messagebox
from tkinter import filedialog
from PIL import Image

def main(): ??
? ? window1 = tk.Tk()
? ? window1.title('')
? ? window1.geometry('200x100')

? ? l1 = tk.Label(window1, bg = 'green', font = ('宋體', 12), width = 50, text = '圖片轉(zhuǎn)換精靈(v1.3)')
? ? l1.pack()

? ? def select_image():
? ? ? ? image = tk.filedialog.askopenfilenames(title = '選擇圖片')
? ? ? ? num = len(image)
? ? ? ? types = ['.jpg', '.png', '.tif', '.gif']
? ? ? ? image_list = list(image)
? ? ? ??
? ? ? ? window2 = tk.Tk()
? ? ? ? window2.title('')
? ? ? ? window2.geometry('200x250')
? ? ? ??
? ? ? ? l2_1 = tk.Label(window2, bg = 'green', font = ('宋體', 12), width = 50, text = '圖片轉(zhuǎn)換精靈(v1.3)')
? ? ? ? l2_1.pack()

? ? ? ? l2_2 = tk.Label(window2, text = '')
? ? ? ? l2_2.pack()
? ? ? ??
? ? ? ? l2_3 = tk.Label(window2, font = ('宋體', 12), width = 50, text = '')
? ? ? ? l2_3.pack()
? ? ? ? l2_3.config(text = '已選擇%d張圖片' % num)
? ? ? ??
? ? ? ? l2_4 = tk.Label(window2, font = ('宋體', 12), width = 50, text = '目標(biāo)格式【點(diǎn)擊即開(kāi)始】')
? ? ? ? l2_4.pack()

? ? ? ? l2_5 = tk.Label(window2, text = '')
? ? ? ? l2_5.pack()


? ? ? ? def jpg_type():
? ? ? ? ? ? image_type = types[0]
? ? ? ? ? ? for img in image_list:
? ? ? ? ? ? ? ? f = Image.open(img)
? ? ? ? ? ? ? ? img_name = img[:-4]
? ? ? ? ? ? ? ? try:
? ? ? ? ? ? ? ? ? ? f.save(img_name + image_type)
? ? ? ? ? ? ? ? except OSError:
? ? ? ? ? ? ? ? ? ? tkinter.messagebox.showerror(title='', message='%s轉(zhuǎn)換出錯(cuò)' % img)

? ? ? ? ? ? tkinter.messagebox.showinfo(title='', message='轉(zhuǎn)換完成') ? ? ??

? ? ? ? def png_type():
? ? ? ? ? ? image_type = types[1]
? ? ? ? ? ? for img in image_list:
? ? ? ? ? ? ? ? f = Image.open(img)
? ? ? ? ? ? ? ? img_name = img[:-4]
? ? ? ? ? ? ? ? try:
? ? ? ? ? ? ? ? ? ? f.save(img_name + image_type)
? ? ? ? ? ? ? ? except OSError:
? ? ? ? ? ? ? ? ? ? tkinter.messagebox.showerror(title='', message='%s轉(zhuǎn)換出錯(cuò)' % img)

? ? ? ? ? ? tkinter.messagebox.showinfo(title='', message='轉(zhuǎn)換完成') ? ? ??

? ? ? ? def tif_type():
? ? ? ? ? ? image_type = types[2]
? ? ? ? ? ? for img in image_list:
? ? ? ? ? ? ? ? f = Image.open(img)
? ? ? ? ? ? ? ? img_name = img[:-4]
? ? ? ? ? ? ? ? try:
? ? ? ? ? ? ? ? ? ? f.save(img_name + image_type)
? ? ? ? ? ? ? ? except OSError:
? ? ? ? ? ? ? ? ? ? tkinter.messagebox.showerror(title='', message='%s轉(zhuǎn)換出錯(cuò)' % img)
? ? ? ? ? ? ? ??
? ? ? ? ? ? tkinter.messagebox.showinfo(title='', message='轉(zhuǎn)換完成') ? ? ??

? ? ? ? def gif_type():
? ? ? ? ? ? image_type = types[3]
? ? ? ? ? ? for img in image_list:
? ? ? ? ? ? ? ? f = Image.open(img)
? ? ? ? ? ? ? ? img_name = img[:-4]
? ? ? ? ? ? ? ? try:
? ? ? ? ? ? ? ? ? ? f.save(img_name + image_type)
? ? ? ? ? ? ? ? except OSError:
? ? ? ? ? ? ? ? ? ? tkinter.messagebox.showerror(title='', message='%s轉(zhuǎn)換出錯(cuò)' % img)

? ? ? ? ? ? tkinter.messagebox.showinfo(title='', message='轉(zhuǎn)換完成') ? ? ??

? ? ? ? button2_1 = tk.Button(window2, text = 'JEPG', font = ('宋體', 12), width = 8, height = 1, command = jpg_type)
? ? ? ? button2_1.pack()
? ? ? ? button2_2 = tk.Button(window2, text = 'PNG', font = ('宋體', 12), width = 8, height = 1, command = png_type)
? ? ? ? button2_2.pack()
? ? ? ? button2_3 = tk.Button(window2, text = 'TIF', font = ('宋體', 12), width = 8, height = 1, command = tif_type)
? ? ? ? button2_3.pack()
? ? ? ? button2_4 = tk.Button(window2, text = 'GIF', font = ('宋體', 12), width = 8, height = 1, command = gif_type)
? ? ? ? button2_4.pack()
? ? ? ??
? ? ? ? window2.mainloop()
? ? ? ? ? ? ? ?
? ? botton1 = tk.Button(window1, text = '選擇圖片', font = ('宋體', 12), width = 8, height = 1, command = select_image)
? ? botton1.place(x = 65, y = 40)

? ? window1.mainloop()

if __name__ == '__main__':
? ? main()

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • 深入了解Python?中線程和進(jìn)程區(qū)別

    深入了解Python?中線程和進(jìn)程區(qū)別

    這篇文章主要介紹了深入了解Python?中線程和進(jìn)程區(qū)別,一個(gè)進(jìn)程由一個(gè)或者多個(gè)線程組成,線程是一個(gè)進(jìn)程中代碼的不同執(zhí)行路線。切換進(jìn)程需要的資源比切換線程的要多的多,下面來(lái)了解更多的詳細(xì)內(nèi)容,需要的小伙伴可以參考一下
    2022-03-03
  • 使用Python繪制可愛(ài)的招財(cái)貓

    使用Python繪制可愛(ài)的招財(cái)貓

    招財(cái)貓,也被稱為“幸運(yùn)貓”,是一種象征財(cái)富和好運(yùn)的吉祥物,經(jīng)常出現(xiàn)在亞洲文化的商店、餐廳和家庭中,今天,我將帶你用 Python 和 matplotlib 庫(kù)從零開(kāi)始繪制一只可愛(ài)的卡通招財(cái)貓,感興趣的小伙伴跟著小編一起來(lái)看看吧
    2025-01-01
  • 使用Python實(shí)現(xiàn)BT種子和磁力鏈接的相互轉(zhuǎn)換

    使用Python實(shí)現(xiàn)BT種子和磁力鏈接的相互轉(zhuǎn)換

    這篇文章主要介紹了使用Python實(shí)現(xiàn)BT種子和磁力鏈接的相互轉(zhuǎn)換的方法,有時(shí)比如迅雷無(wú)法加載磁力鏈接或者無(wú)法上傳附件分享時(shí)可以用到,需要的朋友可以參考下
    2015-11-11
  • python中subprocess實(shí)例用法及知識(shí)點(diǎn)詳解

    python中subprocess實(shí)例用法及知識(shí)點(diǎn)詳解

    在本篇文章里小編給大家分享的是關(guān)于python中subprocess實(shí)例用法及知識(shí)點(diǎn)詳解內(nèi)容,有需要的朋友們可以跟著學(xué)習(xí)下。
    2021-10-10
  • Python3 執(zhí)行Linux Bash命令的方法

    Python3 執(zhí)行Linux Bash命令的方法

    今天小編就為大家分享一篇Python3 執(zhí)行Linux Bash命令的方法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧
    2019-07-07
  • 詳解用python實(shí)現(xiàn)基本的學(xué)生管理系統(tǒng)(文件存儲(chǔ)版)(python3)

    詳解用python實(shí)現(xiàn)基本的學(xué)生管理系統(tǒng)(文件存儲(chǔ)版)(python3)

    這篇文章主要介紹了python實(shí)現(xiàn)基本的學(xué)生管理系統(tǒng),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧
    2019-04-04
  • python實(shí)現(xiàn)拉普拉斯特征圖降維示例

    python實(shí)現(xiàn)拉普拉斯特征圖降維示例

    今天小編就為大家分享一篇python實(shí)現(xiàn)拉普拉斯特征圖降維示例,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧
    2019-11-11
  • pandas.DataFrame寫入數(shù)據(jù)庫(kù)的實(shí)現(xiàn)方式

    pandas.DataFrame寫入數(shù)據(jù)庫(kù)的實(shí)現(xiàn)方式

    這篇文章主要介紹了pandas.DataFrame寫入數(shù)據(jù)庫(kù)的實(shí)現(xiàn)方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2023-08-08
  • 深入淺析python的第三方庫(kù)pandas

    深入淺析python的第三方庫(kù)pandas

    這篇文章主要介紹了python的第三方庫(kù)pandas的相關(guān)知識(shí),本文給大家介紹的非常詳細(xì),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2020-02-02
  • Python PIL庫(kù)圖片灰化處理

    Python PIL庫(kù)圖片灰化處理

    這篇文章主要介紹了Python圖片灰化處理PIL庫(kù)的相關(guān)知識(shí),本文通過(guò)實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下
    2020-04-04

最新評(píng)論