python - 如何在 tkinter 中通过线程打开多个框架?

标签 python tkinter

我试图通过多个线程打开多个框架。 这是我的代码。

'''
This is the module for test and studying.
Author:Roger
Date: 2010/10/10
Python version: 2.6.5
'''


import threading, Tkinter


class Application(Tkinter.Frame):
    def __init__(self, master=None):
        Tkinter.Frame.__init__(self, master)
        self.columnconfigure(50)
        self.rowconfigure(50)
        self.grid()
        self.createWidgets()
        self.mainloop()

    def createWidgets(self):
        self.quitButton = Tkinter.Button (self, text='Quit', command=self.quit )
        self.quitButton.grid()


class lab_404(threading.Thread):
    '''
    Is this the doc_string of lab_404?

    Can there be mutiple_window?
    I do know why is it like this?
    Why is the button still on the frame?
    '''

    myWindow = None

    def __init__(self, computer = 10, server = None, table = 1, chair = 1, student = 2, myWindow = None):
        threading.Thread.__init__(self)
        self.__computer = computer
        self.__server = server
        self.__table = table
        self.__chair = chair
        self.__student = student
        self.myWindow = Application()
        #self.myWindow.mainloop()    #mainloop method is here, I don't where to put it.

    def getComputer(self):
        return self.__computer

    def getServer(self):
        return self.__server

    def getMyWindow(self):
        return self.myWindow


    def setServer(self, Server):
        self.__server = Server


    def run(self):
        print super(lab_404, self).getName(), 'This thread is starting now!'
        print super(lab_404, self).getName(), 'This thread is ending.'


if __name__ == '__main__':
    for n in xrange(1, 10, 1):
        tn = lab_404(server = n)  #Try to make a loop.
        tn.start()

上面的代码一直作为一个框架运行,然后停止(mainloop?)。在我关闭前一个窗口之前,它不会继续下一帧。很合适。 我怎样才能让它自动打开新的框架?

最佳答案

我不认为你可以为所欲为。一般来说,不需要运行多个框架和多个事件循环。您可以在单个线程和单个事件循环中拥有多个帧。

关于python - 如何在 tkinter 中通过线程打开多个框架?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4123409/

相关文章:

navigation - 解决方案 : Python3 Tkinter Jump from one window to another with back and next buttons

python - 有没有办法获得框架 child 的引用?

python - 如何从窗口中删除 Tkinter 小部件?

python - 如何跟踪 "calling chain"从 numpy 到 C 的实现?

python - 在 docker 中运行时无法从 python 连接到 influxdb

Python:TypeError:类型 'NoneType' 的参数不是可迭代的 Spider 脚本问题

python - 在没有 root 访问权限的情况下安装 setuptools python 模块的简单方法?

python - iPython 文件路径自动补全

python - 按下键盘按键时 Tkinter 无法关闭图像

python - 暂停后重新启动时间