Tk() 类的每个实例是否彼此独立运行? [英] Is each instance of Tk() class running independent of each other?

查看:24
本文介绍了Tk() 类的每个实例是否彼此独立运行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在学习如何使用 Tkinter 制作 GUI,但我遇到了一个问题.当我测试程序时,我经常最终构建代码,而它的一个实例已经存在于后台.这两者在执行其功能方面是否相互独立?我一直读到,当我创建 Tk() 的实例然后运行它的 mainloop() 时,这就是所有事情的处理.如果每个循环都属于不同的 Tk() 实例,我可以运行两个或多个循环吗?

I have been learning how to make GUIs with Tkinter and a question has occurred to me. As I'm testing the program, I often end up building the code while an instance of it already exists in the background. Are these two independent of each other in terms of performing their functions? I've always read that when I create the instance of the Tk() and then run its mainloop(), that is what takes care of everything. Can I have two or more loops running if each pertains to a different Tk() instance?

推荐答案

Tk 的每个实例都与 Tk 的任何其他实例分开.它获得自己的底层 tcl 解释器副本.Tk 在同一进程中的两个实例意味着您有两个活动的 tcl 解释器.

Each instance of Tk is separate from any other instance of Tk. It gets its own copy of an underlying tcl interpreter. Two instance of Tk in the same process means you have two active tcl interpreters.

作为一般规则,您应该只拥有一个 Tk 实例,但我想如果您完全了解它们的工作原理,应该可以拥有两个或更多实例.

As a general rule you should only ever have exactly one instance of Tk, but I suppose if you fully understand how they work, it should be possible to have two or more.

我认为这属于您不应该做的事情的范畴,除非您明白为什么不应该做这些事情.一旦你明白了,你就不想去做了.

I think this falls into the category of things you shouldn't do until you understand why you shouldn't do them. And once you understand, you won't want to do it.

这篇关于Tk() 类的每个实例是否彼此独立运行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆