2

I've made this converter. I want it to convert decimal values into binary and hexadecimal using Tkinter.. I made a text input box but I don't know how to get the input values from the input box. We aren't supposed to use OOP so we can't use classes. Here is my code (it's in french for some parts) :

import tkinter as tk
from tkinter import *

def ConverterWind():

    convertisseur = Tk()
    convertisseur.title("Convertisseur")

    inputZone = Text(convertisseur, height=2, width=50)
    inputZone.pack()
    getTextArea = Button(convertisseur, text = "Convertir !", command = getText)
    getTextArea.pack()

    convertisseur.mainloop


MainMenu = Tk()
MainMenu.title("Choix de Modes")

button1 = Button(MainMenu, text = "convertisseur", command = ConverterWind)
button1.pack(side = LEFT, padx= 10, pady = 10)

button2 = Button(MainMenu, text = "QUITTER", command = MainMenu.destroy)
button2.pack(side = RIGHT, padx= 10, pady = 10)

MainMenu.mainloop()
Ajay Pun Magar
  • 425
  • 2
  • 13
  • It is better to use `Entry` widget instead of `Text` widget if you just want to get a value string. Then you can use `inputZone.get()` (assume `inputZone` is now an `Entry` widget) to get the string content. Also it is better to use `Toplevel` instead of `Tk` when opening child window. – acw1668 Sep 28 '22 at 06:47

1 Answers1

0

You can use the Text.get(Index1,Index2) to get the text from Text widget

Try this.

import tkinter as tk
from tkinter import *


def getText(inputText):
    print(inputText.get(1.0,END))

def ConverterWind():

    convertisseur = Tk()
    convertisseur.title("Convertisseur")

    inputZone = Text(convertisseur, height=2, width=50)
    inputZone.pack()
    getTextArea = Button(convertisseur, text = "Convertir !", command = lambda: getText(inputZone))
    getTextArea.pack()

    convertisseur.mainloop


MainMenu = Tk()
MainMenu.title("Choix de Modes")

button1 = Button(MainMenu, text = "convertisseur", command = ConverterWind)
button1.pack(side = LEFT, padx= 10, pady = 10)

button2 = Button(MainMenu, text = "QUITTER", command = MainMenu.destroy)
button2.pack(side = RIGHT, padx= 10, pady = 10)

MainMenu.mainloop()

codester_09
  • 5,622
  • 2
  • 5
  • 27