ashkl ashkl - 1 year ago 68
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)


if __name__ == "__main__":
root = tk.Tk()
root.title("Daily Accounts")
app = emailFrame(root)

This is what is returned:

================== RESTART: H:/Python Program Code/ ==================

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:

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download