如何使用Python制作ASCII码转换器
发表于:2025-02-07 作者:千家信息网编辑
千家信息网最后更新 2025年02月07日,这篇文章主要为大家展示了"如何使用Python制作ASCII码转换器",内容简而易懂,条理清晰,希望能够帮助大家解决疑惑,下面让小编带领大家一起研究并学习一下"如何使用Python制作ASCII码转换
千家信息网最后更新 2025年02月07日如何使用Python制作ASCII码转换器
这篇文章主要为大家展示了"如何使用Python制作ASCII码转换器",内容简而易懂,条理清晰,希望能够帮助大家解决疑惑,下面让小编带领大家一起研究并学习一下"如何使用Python制作ASCII码转换器"这篇文章吧。
实现效果
使用 chr 和 ord 进行互转,
prtint(chr(98))
结果:b
print(ord(b))
结果:98
实现步骤
导入模块
import tkinterfrom 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 tkinterfrom 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码转换器"这篇文章的所有内容,感谢各位的阅读!相信大家都有了一定的了解,希望分享的内容对大家有所帮助,如果还想学习更多知识,欢迎关注行业资讯频道!
字符
信息
输入
画布
图片
程序
错误
运行
转换器
制作
内容
文件
篇文章
上端
图标
结果
页面
学习
帮助
代码
数据库的安全要保护哪些东西
数据库安全各自的含义是什么
生产安全数据库录入
数据库的安全性及管理
数据库安全策略包含哪些
海淀数据库安全审计系统
建立农村房屋安全信息数据库
易用的数据库客户端支持安全管理
连接数据库失败ssl安全错误
数据库的锁怎样保障安全
数据库技术服务公司
信息服务器怎么安装
中信银行总行和软件开发中心
男软件开发容易找女朋友吗
网络安全竞答活动感想
网络安全有关规定
古交软件开发加盟
青岛商城软件开发外包公司
网络安全教育有关视频
滦州电子网络技术售后保障
汽车控制器软件开发工程师待遇
软件开发助理这个工作好找吗
中国互联网科技公司排行
服务器ip不通
网络安全等级保护条例颁布
我的世界网易快速删除服务器账号
唐海租房软件开发
数据库表关闭
浪潮服务器导轨安装教学
网络安全讲师介绍
自己搭建excel服务器
如何恢复数据库
全文数据库的检索方法有哪些
成都工控软件开发哪家好
山东邮件营销外贸软件开发公司
数据库分区设置
汽车控制器软件开发工程师待遇
tp数据库备份
深圳市良康网络技术
前山租房软件开发