Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/334.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 将接收到的数据(从Twisted)写入tkinter TextBox_Python_Tkinter_Twisted_Textfield_Reactor - Fatal编程技术网

Python 将接收到的数据(从Twisted)写入tkinter TextBox

Python 将接收到的数据(从Twisted)写入tkinter TextBox,python,tkinter,twisted,textfield,reactor,Python,Tkinter,Twisted,Textfield,Reactor,好吧,我相信这应该比现在简单,但是。。。 基本上,我有一个扭曲的反应堆监听一个特定的端口。我还有一个包含文本框的tkinter表单。我想做的只是将接收到的数据写入该文本框 以下是我目前的情况: from twisted.web import proxy, http from twisted.internet import reactor from twisted.python import log import ScrolledText import sys #Gui stuff from Tk

好吧,我相信这应该比现在简单,但是。。。 基本上,我有一个扭曲的反应堆监听一个特定的端口。我还有一个包含文本框的tkinter表单。我想做的只是将接收到的数据写入该文本框

以下是我目前的情况:

from twisted.web import proxy, http
from twisted.internet import reactor
from twisted.python import log
import ScrolledText
import sys
#Gui stuff
from Tkinter import *
import ttk
import Tkinter as tk
from ScrolledText import *
import tkMessageBox
from twisted.internet import tksupport

root = Tk()
class MyProxy(proxy.Proxy):
    def dataReceived(self, data):
       print data
       textfield.delete(0,END)
       textfield.insert(0, data)
       textfield.pack()
       return proxy.Proxy.dataReceived(self, data)

class ProxyFactory(http.HTTPFactory):
    protocol=MyProxy

def guiLoop():
    print "[+] Drawing GUI"
    menubar = Menu(root)
    connectMenu = Menu(menubar, tearoff=0)
    connectMenu.add_command(label="Help")  
    connectMenu.add_command(label="About")
    menubar.add_cascade(label="Proxy", menu=connectMenu)
    root.minsize(300,300)
    root.geometry("500x500")
    root.textfield = ScrolledText()
    root.textfield.pack()
    #top = Tk()
    root.title("Proxy")
    root.config(menu=menubar)
    tksupport.install(root)

def main():
    #runReactor()
    factory = ProxyFactory()
    reactor.listenTCP(8080, factory)
    reactor.callLater(0, guiLoop)
    print "[+] Starting Reactor"
    reactor.run()

if __name__ == "__main__":
    main()
我环顾四周,但似乎没有明确的方法显示如何从不同的函数写入文本框。

没有什么特别的——您只需要对小部件的引用,或者调用对小部件有引用的函数

由于
root
是全局的,文本小部件是
root
的一个属性,因此您应该能够执行以下操作:

root.textfield.delete("1.0", "end")
root.textfield.insert("1.0", data)

你好,布莱恩。这看起来不错,我下班回家后会试试。谢谢