Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # -*- coding: utf-8 -*-
- """
- Created on Fri Jun 2 06:33:22 2023
- Este código permite cambiar un número decimal ingresado por el usuario
- a otras bases, como a Binario, Octal o Hexadecimal.
- Utiliza tkinter para crear una interfaz gráfica.
- @alpfa
- """
- import tkinter as tk
- from tkinter import ttk
- def convert():
- """
- Código que permite el cambio de base 10 a Binario, Octal y Hexadecimal.
- Returns
- -------
- La correspondencia en las bases citadas.
- """
- decimal = int(decimal_entry.get())
- binary = bin(decimal)[2:]
- hexadecimal = hex(decimal)[2:]
- octal = oct(decimal)[2:]
- result_text.delete("1.0", tk.END)
- result_text.insert(tk.END, f"Decimal ingresado: {decimal}\n\n")
- result_text.insert(tk.END, "Conversión a otras bases:\n\n")
- result_text.insert(tk.END, f"Binario (0:b): {binary}\n")
- result_text.insert(tk.END, f"Octal (0:o): {octal}\n")
- result_text.insert(tk.END, f"Hexadecimal (0:x): {hexadecimal}")
- root = tk.Tk()
- root.title("Cambio de Base a Binario, Octal y Hexadecimal")
- mainframe = ttk.Frame(root, padding="3 3 12 12")
- mainframe.grid(column=0, row=0, sticky=(tk.N, tk.W, tk.E, tk.S))
- root.columnconfigure(0, weight=1)
- root.rowconfigure(0, weight=1)
- decimal_label = tk.Label(
- mainframe, text="Cambiar base, ingrese un número Decimal y presione: ")
- decimal_label.grid(column=1, row=2, sticky=tk.W)
- decimal_entry = tk.Entry(mainframe)
- decimal_entry.grid(column=2, row=1, sticky=tk.W)
- convert_button = tk.Button(mainframe, text="Convertir", command=convert)
- convert_button.grid(column=2, row=2, sticky=tk.W)
- result_text = tk.Text(mainframe, height=8, width=50)
- result_text.grid(column=2, row=3, rowspan=4, sticky=(tk.W, tk.E))
- result_text.tag_configure("title", font=("Courier New", 12, "bold"))
- result_text.insert(tk.END, "Resultado:\n", "title")
- root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement