Python Forum

Full Version: Tkinter Textbox only showing one character
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello,
I am writing an ID3 parser from scratch and ever since I made the change to search byte signatures matching an ID3 frame tag so it knew when to stop parsing a tag. However now it only displays the first character in the title name or artist name. The code is shown below here:
Tkinter displayed the entire song title or artist title before I had it search an entire array of ID3 signatures and search for any tag listed in the array such as TIT2 or TSSE instead of just TPE1. All tags in frame tag array shown here in section 4 https://id3.org/id3v2.3.0

I attached a picture so you can get a better idea of what it's doing (right click on it and select open in new tab):

[Image: 10d1udxCt9YuaiJQjgBMfrmcw0gINx70Q]

and here is the code to extract artist information:

def getartist(parsedFile):
    global artistName
    global ArtistInfo
    global artistArray
    global artistStartingIndex
    global nextTagCheck
    global nextTagText
    global artistsName
    artistArray = []
    for s in range(len(parsedFile)):
        if parsedFile[s] == b'T':
            if parsedFile[s + 1] == b'P':
                if parsedFile[s + 2] == b'E':
                    if parsedFile[s + 3] == b'1':
                        artistArray = []
                        artistName = ""
                        artistsName = ""
                        nextTagCheck = []
                        nextTagText = ""
                        ArtistFrameTag = s + 4
                        for i in range(ArtistFrameTag, len(parsedFile)):
                            if str(parsedFile[i].hex()) == "ff":
                                if str(parsedFile[i + 1].hex()) == "fe":
                                    artistStartingIndex = i + 2
                                    for n in range(artistStartingIndex, len(parsedFile)):
                                        if parsedFile[n] != 'b\x00':
                                            nextTagCheck.append(parsedFile[n].decode(encoding="UTF-8"))
                                            nextTagCheck.append(parsedFile[n + 1].decode(encoding="UTF-8"))
                                            nextTagCheck.append(parsedFile[n + 2].decode(encoding="UTF-8"))
                                            nextTagCheck.append(parsedFile[n + 3].decode(encoding="UTF-8"))
                                            nextTag = nextTagText.join(nextTagCheck)
                                            if nextTag in id3Tags:
                                                break
                                            nextTagCheck.clear()

                                            artistArray.append(parsedFile[n].decode(encoding="UTF-8"))
                                break
    print("Artist parsing complete, displaying artist information...")
    if artistArray:
        artistsName = artistName.join(artistArray)
        print("Artist Name:" + artistsName)
        if metadata_text_artist != 0:
            metadata_text_artist.delete(1.0, tk.END)
        metadata_text_artist.insert(tk.END, "Artist Name: " + artistsName)
    else:
        print("Format not recognized or cannot find Artist tag information")
and tkinter root mainloop and update functions are present at the end of the code:

root.deiconify()
root.after_idle(root.attributes, '-topmost', 0)
root.lift()

root.update()

metadata_text_title = tk.Text(root, height=1, width=64)
metadata_text_title.pack()

metadata_text_artist = tk.Text(root, height=1, width=64)
metadata_text_artist.pack()

openFile1 = tk.Button(root, text="Open MP3 File...", command=file1)
openFile1.pack()

compare = tk.Button(root, text="Extract", command=extract)
compare.pack()

root.mainloop()
Foung the Error:

if parsedFile[n] != 'b\x00':
should be:

if parsedFile[n] != b'\x00':
The b (standing for byte) was inside the quotation marks instead of in front

Tkinter was only printing the first character in the artistArray because the second index on the array will not display because it cannot be decoded into UTF-8 string when it is (byte) b'\x00'