我是一个相当新的程序员,如果你能帮助我,我将不胜感激。我看过谷歌,但有一些“Twisted+Tkinter”的例子。当我单击窗口上的“发送”按钮时,我收到此错误:
错误是 e.insert(0,m) AttributeError: 'str' object has no attribute 'insert'
和代码:
from Tkinter import *
from twisted.internet import reactor, tksupport
class App(object):
def onQuit(self):
print "Quit!"
reactor.stop()
def onButton(self):
m=self.entryvar.get()
e=self.labeltext.get()
e.insert(0,m)
def __init__(self, master):
frame = Frame(master)
frame.pack()
self.entryvar=StringVar()
self.mes=Entry(frame,textvariable=self.entryvar)
self.mes.pack()
self.labeltext=StringVar()
self.label=Label(frame,textvariable=self.labeltext)
self.label.pack()
q = Button(frame, text="Quit!", command=self.onQuit)
b = Button(frame, text="Send", command=self.onButton)
q.pack(side=LEFT)
b.pack(side=LEFT)
if __name__ == '__main__':
root = Tk()
tksupport.install(root)
app = App(root)
reactor.run()