In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-30 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly shows you "how to use Python to make ASCII code converter", the content is easy to understand, clear, hope to help you solve your doubts, the following let the editor lead you to study and learn "how to use Python to make ASCII code converter" this article.
Realize the effect
Use chr and ord to transfer each other
Prtint (chr 98)
Results: B
Print (ord (b))
Results: 98
Implementation steps
Import module
Import tkinterfrom tkinter import * from tkinter.ttk import *
Create the canvas and change the background color to add a texture picture. If the picture does not exist, execute exit () to exit the program.
Canvas = tkinter.Canvas (root, bg= "# ebebeb", height=400, width=700, borderwidth=-3) # create canvas canvas.pack (side='top') # place canvas (top) try: image_file = tkinter.PhotoImage (file= ". / Along.png") # load picture file canvas.create_image (0,0, anchor='nw', image=image_file) # put the picture on the canvas except: exit () pass
Add input box and information box
# input information var_Input_information = tkinter.StringVar () tkinter.Entry (root, width=20, borderwidth=1, bg='#ebebeb', textvariable=var_Input_information) .place (xylene 29, yearly 160) # input information var_pick_up_information = tkinter.StringVar () tkinter.Entry (root, width=20, borderwidth=1, bg='#ebebeb', textvariable=var_pick_up_information) .place (xylene 306, yearly 160) # get information var_Input_information_2 = tkinter.StringVar () tkinter.Entry (root, width=20, borderwidth=1, bg='#ebebeb' Textvariable=var_Input_information_2) .place (Xerox 29, yearly 210) # get information var_pick_up_information_2 = tkinter.StringVar () tkinter.Entry (root, width=20, borderwidth=1, bg='#ebebeb', textvariable=var_pick_up_information_2) .place (Xerox 306, yearly 210)
Tagging
Tkinter.Label (canvas, bg= "# ebebeb", text=' ↓↓↓↓') .place (Xerox 364, yearly 184) tkinter.Label (canvas, bg= "# ebebeb", text=' ↓↓↓↓') .place (xylene 84, yearly 184)
ASCII_ord is used to convert characters to ASCII codes, and ASCII_chr is used to convert ASCII codes to characters, the core part.
Def ASCII_ord (): try: ord_ = ord (var_Input_information.get ()) var_Input_information_2.set (ord_) except: var_Input_information_2.set ('incorrect characters or multiple input characters!') 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 ('incorrect characters or multiple input characters!')
Add two buttons
Button (root, text=' characters to ASCII code', command=ASCII_ord) .place (Xerox 55, text='ASCII 240) Button (root, text='ASCII code to character', command=ASCII_chr) .place (Xerox 336, yawn 240)
Executive program
Root.mainloop ()
The program runs:
Complete code import tkinterfrom tkinter import * from tkinter.ttk import * root = Tk () root.title ('cheap workshop-ASCII code conversion') # the title name of the program root.geometry ("480x320+512+288") # the size of the window and the display position of the page root.resizable (False, False) # fixed pages cannot be zoomed in or out of root.iconbitmap ("picture.ico") # the icon of the program canvas = tkinter.Canvas (root, bg= "# ebebeb", height=400, width=700 Borderwidth=-3) # create canvas canvas.pack (side='top') # place canvas (top) try: image_file = tkinter.PhotoImage (file= ". / Along.png") # load picture file canvas.create_image (0,0, anchor='nw', image=image_file) # put pictures on canvas except: exit () pass # input information var_Input_information = tkinter.StringVar () tkinter.Entry (root, width=20, borderwidth=1 Bg='#ebebeb', textvariable=var_Input_information) .place (xdye 29, yearly 160) # input information var_pick_up_information = tkinter.StringVar () tkinter.Entry (root, width=20, borderwidth=1, bg='#ebebeb', textvariable=var_pick_up_information) .place (Xerox 306, yearly 160) # get the information var_Input_information_2 = tkinter.StringVar () tkinter.Entry (root, width=20, borderwidth=1, bg='#ebebeb', textvariable=var_Input_information_2) .place (xcircle 29) ) # get information var_pick_up_information_2 = tkinter.StringVar () tkinter.Entry (root, width=20, borderwidth=1, bg='#ebebeb', textvariable=var_pick_up_information_2) .place (canvas, bg= "# ebebeb", text=' ↓↓↓↓') .place (canvas, bg= "# ebebeb", text=' ↓↓↓↓') .place (Xerox 84) Yellow184) def ASCII_ord (): try: ord_ = ord (var_Input_information.get ()) var_Input_information_2.set (ord_) except: var_Input_information_2.set ('incorrect characters or multiple input characters!') 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 ('incorrect characters or multiple input characters!') Button (root, text=' character to ASCII code', command=ASCII_ord) .place (Xerox 55, YBG 240) Button (root, text='ASCII code to character', command=ASCII_chr) .place (Xerox 336, YBY 240) root.mainloop ()
To pack it up, let's run cmd from the current python root directory
Running instruction
Pyinstaller-I picture.ico ASCII.py-- noconsole
-I add icon
-- the command box does not appear when noconsole runs the program
-F is packaged as a single file
You can see that it's already packed.
The above is all the content of the article "how to use Python to make ASCII Converter". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.