English 中文(简体)
未能与Tkinter GUI合作
原标题:Asyncore not working properly with Tkinter GUI

此时此刻,我仍对全球倡议及网络方案拟定工作持不见态度,因此希望这样做将是非常简单的固定办法。 我非常基本地了解每个单元都建立了几个方案,但我担心在一项方案中同时使用这两个单元。 我把整个倡议聚集在一起,只是发现我无法发挥任何重要的同步网络功能。 为了简明扼要,我把该方案分为最简单的形式,以说明Im的基本问题。 该法典:

from Tkinter import *
import asyncore, socket

class Application(object):
    def __init__(self, root):
        mainFrame = Frame(root)
        mainFrame.grid(column=1, row=1, columnspan=3, rowspan=1)
        mainButton = Button(mainFrame, text= Click , command=self.makeSocket)
        mainButton.grid(column=2, row=1, columnspan=1, rowspan=1, pady=7, padx=40)

    def makeSocket(self):
        clientSocket()

class clientSocket(asyncore.dispatcher):
    def __init__(self):
        asyncore.dispatcher.__init__(self)
        self.create_socket(socket.AF_INET, socket.SOCK_STREAM)
        self.connect(("XXX.XXX.XXX.XXX", XXXX))
        print  init works 

    def handle_connect(self):
        print  connect works 

root = Tk()
myApp = Application(root)
root.after_idle(asyncore.loop) 
root.mainloop()

因此,当我管理该方案并点击了纽特时,我获得了铺设的内it工程,表明客户的袖珍标已经初步形成,连接已经成功。 然而,操作-连接方法运行起来。 如果我采用手法,并在服务器上执行指挥(向客户发送数据),那么这种方法要么被点上。 我认为,有一些一般性问题妨碍作为同分道的人自行经营。 我认识到,近亲事件的圈子可能是主人,但我感觉到,“后_”方法将允许在“全球倡议”闲置时处理非创伤事件。 难道这还会造成问题,还是会成为其他事情吗?

问题回答

这里存在几个问题,我不敢确定问题是什么。

如同同分,当事情正常工作时,这种功能永远不会返回。 根基。 在你关闭窗户之前,主食可能永远不会返回。 因此,情况可能是错误的,因为在某个时候,另一个地方会遭受一段时间的饥饿。

(显然,这就是为什么我不喜欢一些框架,试图通过更换主机和以事件驱动的系统取代主机来方便其使用——在你需要共同使用两个或两个以上系统之前,它发挥了巨大作用,此时此刻,事情可能变得令人迷惑。)

然而,你可以限制同学次数。 休闲会蓬勃发展。 相反:

def poll_asyncore_once():
    asyncore.loop(count=1)

root.after_idle(poll_asyncore_once) 

你们也许希望给 lo带增加时间价值,比起。

然而,我仍然认为,即使德国马克确实由于你进入了同心的圈子而使事件更加恶化,这一联系将最终实现。 这就意味着有些事情已经错了,因此,在连接方法中,可能出现一个例外,而传统知识正在吞.。 Try putting an specialhandler inuserSocket.init and see how You go.

See this recipe by Jacob Hallén show how to use asyncore and Tkinterjoint (basically through means of a threading trick). (该表还作为9.6版面添加到第一期《 Python》印刷版和第二版的11.4版。)





相关问题
Can Django models use MySQL functions?

Is there a way to force Django models to pass a field to a MySQL function every time the model data is read or loaded? To clarify what I mean in SQL, I want the Django model to produce something like ...

An enterprise scheduler for python (like quartz)

I am looking for an enterprise tasks scheduler for python, like quartz is for Java. Requirements: Persistent: if the process restarts or the machine restarts, then all the jobs must stay there and ...

How to remove unique, then duplicate dictionaries in a list?

Given the following list that contains some duplicate and some unique dictionaries, what is the best method to remove unique dictionaries first, then reduce the duplicate dictionaries to single ...

What is suggested seed value to use with random.seed()?

Simple enough question: I m using python random module to generate random integers. I want to know what is the suggested value to use with the random.seed() function? Currently I am letting this ...

How can I make the PyDev editor selectively ignore errors?

I m using PyDev under Eclipse to write some Jython code. I ve got numerous instances where I need to do something like this: import com.work.project.component.client.Interface.ISubInterface as ...

How do I profile `paster serve` s startup time?

Python s paster serve app.ini is taking longer than I would like to be ready for the first request. I know how to profile requests with middleware, but how do I profile the initialization time? I ...

Pragmatically adding give-aways/freebies to an online store

Our business currently has an online store and recently we ve been offering free specials to our customers. Right now, we simply display the special and give the buyer a notice stating we will add the ...

Converting Dictionary to List? [duplicate]

I m trying to convert a Python dictionary into a Python list, in order to perform some calculations. #My dictionary dict = {} dict[ Capital ]="London" dict[ Food ]="Fish&Chips" dict[ 2012 ]="...

热门标签