ashkl ashkl - 9 months ago 31
Python Question

Python - Scrolledtext returning numbers instead of the text

For some reason when i try and print out the text in the scrolledtext widget, i get a string of numbers instead of the text thats meant to be entered.

This is my code:

import tkinter as tk
import tkinter.scrolledtext as st
import time as tm

class emailFrame(tk.Frame):
def __init__(self, master):
self.eframe = tk.Frame(master)
self.eframe.pack(fill="both", expand = True)

text = 'This is a test ' + str(tm.strftime("%d-%m-%Y")) + ' - ' + str(tm.strftime("%A"))

self.emessage = st.ScrolledText(self.eframe, wrap = 'word', width = 50, height = 10)
self.emessage.insert(1.0, text)
self.emessage.pack(padx = 50, pady = 140)

self.msg = self.emessage.get(1.0, tk.END)

body = str(self.emessage)

print(body)

if __name__ == "__main__":
root = tk.Tk()
root.geometry("480x480")
root.title("Daily Accounts")
root.resizable(0,0)
app = emailFrame(root)
root.mainloop()


This is what is returned:

================== RESTART: H:/Python Program Code/test.py ==================
.54904592.54905040
>>>


I'm not sure why this is happening, ive tried to convert it to a string and it still doesn't work.

Answer Source

Just use this:

print(self.msg)