Python - Scrolledtext返回数字而不是文本

时间:2017-03-11 20:41:24

标签: python string return field

出于某种原因,当我尝试打印scrolledtext小部件中的文本时,我得到一串数字而不是要输入的文本。

这是我的代码:

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()

这是返回的内容:

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

我不确定为什么会发生这种情况,我试图将其转换为字符串,但仍然无效。

1 个答案:

答案 0 :(得分:0)

请使用:

print(self.msg)