问题
[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.
[CODE]
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()
[NOTE] I need wxpython because of : GenericDirCtrl object. I did not spot an identical obj in : tkinter, ttk, tix. Keep investigating
回答1:
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.
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.
来源:https://stackoverflow.com/questions/33731192/how-can-i-combine-tkinter-and-wxpython-without-freezing-window-python