最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

基于Python制作ASCII碼轉(zhuǎn)換器

 更新時(shí)間:2022年02月07日 11:26:15   作者:小木_.  
ASCII碼是基于拉丁字母的一套電腦編碼系統(tǒng),主要用于顯示現(xiàn)代英語和其他西歐語言。本文將利用Python制作一個(gè)ASCII碼轉(zhuǎn)換器,感興趣的可以動(dòng)手試一試

實(shí)現(xiàn)效果

使用 chr 和 ord 進(jìn)行互轉(zhuǎn),

prtint(chr(98))    

結(jié)果:b

print(ord(b))

結(jié)果:98

實(shí)現(xiàn)步驟

導(dǎo)入模塊

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

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

canvas = tkinter.Canvas(root, bg="#ebebeb", height=400, width=700, borderwidth=-3)  # 創(chuàng)建畫布
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)

加標(biāo)簽

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

ASCII_ord 是用來字符轉(zhuǎn)ASCII碼的,ASCII_chr是用來ASCII碼轉(zhuǎn)字符的,核心部位

def ASCII_ord():
    try:
        ord_ = ord(var_Input_information.get())
        var_Input_information_2.set(ord_)
    except:
        var_Input_information_2.set('錯(cuò)誤字符或多輸入字符?。。?)
 
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('錯(cuò)誤字符或多輸入字符?。?!')

加倆按鈕

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

執(zhí)行程序

root.mainloop()

程序運(yùn)行:

完整代碼

import tkinter
from tkinter import *
from tkinter.ttk import *
 
 
root = Tk()
root.title('賤工坊-ASCII碼轉(zhuǎn)換')  # 程序的標(biāo)題名稱
root.geometry("480x320+512+288")  # 窗口的大小及頁面的顯示位置
root.resizable(False, False)  # 固定頁面不可放大縮小
root.iconbitmap("picture.ico")  # 程序的圖標(biāo)
 
canvas = tkinter.Canvas(root, bg="#ebebeb", height=400, width=700, borderwidth=-3)  # 創(chuàng)建畫布
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('錯(cuò)誤字符或多輸入字符?。?!')
 
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('錯(cuò)誤字符或多輸入字符!??!')
Button(root, text='字符轉(zhuǎn)ASCII碼', command=ASCII_ord).place(x=55, y=240)
Button(root, text='ASCII碼轉(zhuǎn)字符', command=ASCII_chr).place(x=336, y=240)
root.mainloop()

打包一下,我們?cè)诋?dāng)前python根目錄運(yùn)行cmd

運(yùn)行指令

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

-i  添加圖標(biāo)

--noconsole   運(yùn)行程序時(shí)不出現(xiàn)命令框

-F   打包為單個(gè)文件

可以看到已經(jīng)打包好了

到此這篇關(guān)于基于Python制作ASCII碼轉(zhuǎn)換器的文章就介紹到這了,更多相關(guān)Python ASCII碼轉(zhuǎn)換器內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評(píng)論

弥渡县| 吉木乃县| 广东省| 贵德县| 安陆市| 临高县| 东光县| 当阳市| 香格里拉县| 巴中市| 沧源| 东宁县| 东丽区| 湖南省| 大冶市| 台湾省| 迁安市| 赣州市| 福鼎市| 涟水县| 乐安县| 连云港市| 盐山县| 霍城县| 定边县| 浦北县| 重庆市| 叙永县| 武城县| 通化县| 荣昌县| 三门县| 景谷| 临海市| 文水县| 石屏县| 常山县| 江陵县| 获嘉县| 南投县| 桐柏县|