日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > python >内容正文

python

【Python ASCII码转换】——制作ASCII码转换程序,并打包为应用程序

發布時間:2023/12/20 python 29 豆豆
生活随笔 收集整理的這篇文章主要介紹了 【Python ASCII码转换】——制作ASCII码转换程序,并打包为应用程序 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

點個贊留個關注吧!!

?

使用 chr 和 ord 進行互轉,

prtint(chr(98))? ??

結果:b

print(ord(b))

結果:98

導入模塊

import tkinter from tkinter import * from tkinter.ttk import *

創建畫布并更改背景顏色添加紋理圖片,如果圖片不存在則執行exit()進行退出程序

canvas = tkinter.Canvas(root, bg="#ebebeb", height=400, width=700, borderwidth=-3) # 創建畫布 canvas.pack(side='top') # 放置畫布(為上端) try:image_file = tkinter.PhotoImage(file="./Along.png") # 加載圖片文件canvas.create_image(0, 0, anchor='nw', image=image_file) # 將圖片置于畫布上 except:exit()pass

添加輸入框和信息框

#輸入信息 var_Input_information = tkinter.StringVar() tkinter.Entry(root, width=20, borderwidth=1, bg='#ebebeb', textvariable=var_Input_information).place(x=29, y=160)#輸入信息 var_pick_up_information = tkinter.StringVar() tkinter.Entry(root, width=20, borderwidth=1, bg='#ebebeb', textvariable=var_pick_up_information).place(x=306, y=160)#獲取信息 var_Input_information_2 = tkinter.StringVar() tkinter.Entry(root, width=20, borderwidth=1, bg='#ebebeb', textvariable=var_Input_information_2).place(x=29, y=210)#獲取信息 var_pick_up_information_2 = tkinter.StringVar() tkinter.Entry(root, width=20, borderwidth=1, bg='#ebebeb', textvariable=var_pick_up_information_2).place(x=306, y=210)

加標簽

tkinter.Label(canvas, bg="#ebebeb", text='↓↓↓↓').place(x=364, y=184) tkinter.Label(canvas, bg="#ebebeb", text='↓↓↓↓').place(x=84, y=184)

ASCII_ord 是用來字符轉ASCII碼的,ASCII_chr是用來ASCII碼轉字符的,核心部位

def ASCII_ord():try:ord_ = ord(var_Input_information.get())var_Input_information_2.set(ord_)except:var_Input_information_2.set('錯誤字符或多輸入字符!!!')def ASCII_chr():try:chr_ = chr(int(var_pick_up_information.get()))var_pick_up_information_2.set(chr_)except:var_pick_up_information_2.set('錯誤字符或多輸入字符!!!')

加倆按鈕

Button(root, text='字符轉ASCII碼', command=ASCII_ord).place(x=55, y=240) Button(root, text='ASCII碼轉字符', command=ASCII_chr).place(x=336, y=240)

執行程序

root.mainloop()

程序運行:

?完整代碼:

import tkinter from tkinter import * from tkinter.ttk import *root = Tk() root.title('賤工坊-ASCII碼轉換') # 程序的標題名稱 root.geometry("480x320+512+288") # 窗口的大小及頁面的顯示位置 root.resizable(False, False) # 固定頁面不可放大縮小 root.iconbitmap("picture.ico") # 程序的圖標canvas = tkinter.Canvas(root, bg="#ebebeb", height=400, width=700, borderwidth=-3) # 創建畫布 canvas.pack(side='top') # 放置畫布(為上端) try:image_file = tkinter.PhotoImage(file="./Along.png") # 加載圖片文件canvas.create_image(0, 0, anchor='nw', image=image_file) # 將圖片置于畫布上 except:exit()pass#輸入信息 var_Input_information = tkinter.StringVar() tkinter.Entry(root, width=20, borderwidth=1, bg='#ebebeb', textvariable=var_Input_information).place(x=29, y=160)#輸入信息 var_pick_up_information = tkinter.StringVar() tkinter.Entry(root, width=20, borderwidth=1, bg='#ebebeb', textvariable=var_pick_up_information).place(x=306, y=160)#獲取信息 var_Input_information_2 = tkinter.StringVar() tkinter.Entry(root, width=20, borderwidth=1, bg='#ebebeb', textvariable=var_Input_information_2).place(x=29, y=210)#獲取信息 var_pick_up_information_2 = tkinter.StringVar() tkinter.Entry(root, width=20, borderwidth=1, bg='#ebebeb', textvariable=var_pick_up_information_2).place(x=306, y=210)tkinter.Label(canvas, bg="#ebebeb", text='↓↓↓↓').place(x=364, y=184) tkinter.Label(canvas, bg="#ebebeb", text='↓↓↓↓').place(x=84, y=184)def ASCII_ord():try:ord_ = ord(var_Input_information.get())var_Input_information_2.set(ord_)except:var_Input_information_2.set('錯誤字符或多輸入字符!!!')def ASCII_chr():try:chr_ = chr(int(var_pick_up_information.get()))var_pick_up_information_2.set(chr_)except:var_pick_up_information_2.set('錯誤字符或多輸入字符!!!') Button(root, text='字符轉ASCII碼', command=ASCII_ord).place(x=55, y=240) Button(root, text='ASCII碼轉字符', command=ASCII_chr).place(x=336, y=240) root.mainloop()

打包一下,我們在當前python根目錄運行cmd

?

運行指令

pyinstaller -i picture.ico ASCII.py --noconsole

-i? 添加圖標

--noconsole? ?運行程序時不出現命令框

-F? ?打包為單個文件

可以看到已經打包好了

總結

以上是生活随笔為你收集整理的【Python ASCII码转换】——制作ASCII码转换程序,并打包为应用程序的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。