Monday, 24 January 2022

Write Python GUI program to accept a decimal number and convert and display it to binary, octal and hexadecimal number.

Slip 27 Q 2

CODE :

from tkinter import *
from tkinter import messagebox

def clearAll() :
    numberField.delete(0, END)
    binaryField.delete(0, END)
    octalField.delete(0, END)
    hexadecimalField.delete(0, END)

def checkError() :

    if (numberField.get() == "") :

        messagebox.showerror("Input Error")

        clearAll()
       
        return -1

def calculateAge() :

    value = checkError()

    if value == -1 :
        return
   
    else :
       
        number0 = int(numberField.get())
        binary=(bin(number0)[2:])
        octal =oct(number0)[2:]
        hexadecimal=hex(number0)[2:]

        binaryField.insert(10, str(binary))
        octalField.insert(10, str(octal))
        hexadecimalField.insert(10, str(hexadecimal))
   
if __name__ == "__main__" :

    gui = Tk()
    gui.configure(background = "light green")
    gui.title("decimal number converter")
    gui.geometry("400x200")
 
 
 
    number = Label(gui, text = "Give number", bg = "#00ffff")
    number1 = Label(gui, text = "number", bg = "light green")
    numberField = Entry(gui)

    result = Label(gui, text = "result", bg = "#00ffff")

    resultbutton = Button(gui, text = "Result button", fg = "Black",
    bg = "gray", command = calculateAge)

    resultbinary = Label(gui, text = "result binary", bg = "light green")
    resultoctal = Label(gui, text = "result cotal", bg = "light green")
    resulthexadecimal = Label(gui,text ="resulthexadecimal",bg = "light green")

    binaryField = Entry(gui)
    octalField = Entry(gui)
    hexadecimalField = Entry(gui)
   
    clearAllEntry = Button(gui, text = "Clear All", fg = "Black",
    bg = "Red", command = clearAll)

    number.grid(row = 0, column = 1)
    number1.grid(row = 1, column = 1)
    numberField.grid(row = 2, column = 1)
   
    result.grid(row = 3, column = 1)
    resultbutton.grid(row = 4, column = 1)
   
    resultbinary.grid(row = 5, column = 0)
    binaryField.grid(row = 6, column = 0)
   
    resultoctal.grid(row = 5, column = 1)
    octalField.grid(row = 6, column = 1)
 
    resulthexadecimal.grid(row = 5, column = 2)
    hexadecimalField.grid(row = 6, column = 2)
 
    clearAllEntry.grid(row = 7, column = 1)

    gui.mainloop()

OUTPUT:



No comments:

Post a Comment

Write a Java program to display given extension files from a specific directory on server machine.

 DOWNLOAD     SLIP14Q2 /** * STEPS TO RUN CODE * Step 01 compile the code * Step 02 run the code * Step 03 give a file directory locatio...