정보통신기술(ICT)

문자를 숫자로 변환하는 파이썬 GUI 프로그램

해머슴 2024. 11. 20. 19:38
import tkinter as tk
from tkinter import messagebox

def convert_to_numbers():
    input_text = entry.get()
    if not input_text:
        messagebox.showerror("Error", "Please enter some text.")
        return
   
    # Convert each character to its ASCII value
    converted_numbers = [str(ord(char)) for char in input_text]
    result.set(" ".join(converted_numbers))

# GUI setup
window = tk.Tk()
window.title("Text to Numbers Converter")
window.geometry("400x200")

# Input field
tk.Label(window, text="Enter text:").pack(pady=5)
entry = tk.Entry(window, width=30)
entry.pack(pady=5)

# Convert button
tk.Button(window, text="Convert", command=convert_to_numbers).pack(pady=10)

# Result display
result = tk.StringVar()
tk.Label(window, text="Converted Numbers:").pack(pady=5)
result_label = tk.Label(window, textvariable=result, wraplength=350)
result_label.pack(pady=5)

# Run the GUI event loop
window.mainloop()