from tkinter import *
import tkinter as tk
def text_to_binary(convert):
for x in convert: # iterates over each character in the list
ascii_values = ord(x) #gets the ascii value for x
binary = format(ascii_values,'b')
if len(binary) == 7:
tk.Label(text="'0',binary")
tk.Label.pack()
elif len(binary) == 6:
tk.Label(text="'00',binary")
tk.Label.pack()
else:
tk.Label(text=binary)
tk.Label.pack()
###MAINLINE###
window = tk.Tk()
window.title('Binary Converter')
window.geometry("450x120")
entry = tk.Entry(width=50)
entry.pack()
result = entry.get()
btn_convert = tk.Button(text='Convert it!', command=text_to_binary(result))
btn_convert.pack()
window.mainloop()
I'm not sure what I'm doing wrong. I want to use the function I created to convert bianry, it does that, but I don't know how to get that running with tkinter gui. Little help?