如何在不冻结窗口的情况下结合 tkinter 和 wxpython - python? [英] How can I combine tkinter and wxpython without freezing window - python?

查看:38
本文介绍了如何在不冻结窗口的情况下结合 tkinter 和 wxpython - python?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

[问题]如果我结合 tkinter 和 wxpython 那么应用程序.窗口会冻结.因此,请分享一个提示.我认为它与线程有关,但我无法完全理解它.

[PROBLEM] If I combine tkinter and wxpython then the app. window will freeze. Therefore please share a hint. I reckon that it has something to do with threads but I cannot quite put my finger on it.

[代码]

from Tkinter import *
master = Tk()


def getFiles():
    import wx
    app = wx.App(False)  
    locale = wx.Locale(wx.LANGUAGE_ENGLISH)
    frame = wx.Frame(None, wx.ID_ANY, "test", style=wx.MINIMIZE_BOX | wx.SYSTEM_MENU | wx.CAPTION | wx.CLOSE_BOX | wx.CLIP_CHILDREN) 
    frame.Center()
    frame.SetBackgroundColour('LIGHTGREY')
    frame.SetSize(200,400)
    # Create grid manager instance
    sizer = wx.GridBagSizer()
    # Create Label for: Available testcase
    entry = wx.StaticText( frame, wx.ID_ANY, u"Available testcases:", wx.DefaultPosition, wx.DefaultSize, 0 )
    sizer.Add(entry,(1,1),(1,1),wx.EXPAND)
    frame.SetSizerAndFit(sizer)
    frame.Show(True)     # Show the frame.
    app.MainLoop()

b = Button(master, text="OK", command=lambda : getFiles())
b.pack()
master.mainloop()

[注意]我需要 wxpython 因为:GenericDirCtrl 对象.我没有在 tkinter、ttk、tix 中发现相同的 obj.继续调查

[NOTE] I need wxpython because of : GenericDirCtrl object. I did not spot an identical obj in : tkinter, ttk, tix. Keep investigating

推荐答案

您不能将 tkinter 和 wxPython 结合使用.它们都是具有自己的事件循环的 GUI 工具包,它们基本上是处理来自小部件的事件的无限循环.您不能同时运行两个无限循环.

You cannot combine tkinter and wxPython. They are both GUI toolkits with their own event loops, which are basically infinite loops processing events from widgets. You cannot run two infinite loops at once.

但是,可能也没有理由同时运行两者.如果您需要一个 tkinter 中不存在的小部件,只需使用 wxPython 构建您的整个应用程序.

However, there is probably also no reason to run both at once. If you need a widget which is not present in tkinter, just build your whole application with wxPython.

这篇关于如何在不冻结窗口的情况下结合 tkinter 和 wxpython - python?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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