I’been working on wxpython for the last 2 months or so for a final project at school, the problem I have is to make it work beside TkInter, the GUI by default on python. It almost work fine, but when a window of wx is open the part programmed on tkinter becomes weird, don’t do nothing until the wx window is closed, it don’t affect directly the usability of the program, but our teacher said it can’t happen so... there is a way to make the both interfaces work togueter?
Something else I can say is that the both windows aren’t related, the only thing I need is that the both can work without interruptions
Manuel Pérez wrote:
I’been working on wxpython for the last 2 months or so for a final project at school, the problem I have is to make it work beside TkInter, the GUI by default on python. It almost work fine, but when a window of wx is open the part programmed on tkinter becomes weird, don’t do nothing until the wx window is closed, it don’t affect directly the usability of the program, but our teacher said it can’t happen so... there is a way to make the both interfaces work togueter?
You need both to work in a single application? There is very little
chance of that working, and the result you got is exactly what I would
expect. The issue is messages. All of the major GUI architectures
today are message driven; all the APIs you call eventually turn into
window messages that get sent to the window's thread. A GUI application
needs to have a "main loop", which receives, translates and dispatches
those messages. Both wx and tk expect to be in full control of their
message loops.
Now, having said that, you might be able to make this work by launching
your Tk windows from a separate thread. Many people don't realize that
each window is associated with a thread, and all messages for a window
are sent to the message loop in that thread. So, if you created all
your wx windows in one thread and run wxApp.MainLoop there, and create
your Tk windows in another thread and run tk.mainloop there, you could
make this work. You'd have to be a bit careful about communicating back
and forth, but it could be done.
Why do you need to do this? Why wouldn't you just translate the Tk
windows into wx?
And, by the way, saying "TkInter, the GUI by default on python" is a bit
misleading. TkInter happens to be included with the standard library,
but it's not the "preferred" GUI by any means. It's there because it
was first (way, WAY back -- 25 years ago).
···
--
Tim Roberts, timr@probo.com
Providenza & Boekelheide, Inc.
As both need their own main loop your best bet is to have the two
running as separate processes, (basically separate programs), with
either the wx UI launching the TkInter or vice-versa. As you say they
are not related presumably they do not share any data so this should not
be a problem.
···
On 14/05/2018 16:14, Manuel Pérez wrote:
I’been working on wxpython for the last 2 months or so for a final project at school, the problem I have is to make it work beside TkInter, the GUI by default on python. It almost work fine, but when a window of wx is open the part programmed on tkinter becomes weird, don’t do nothing until the wx window is closed, it don’t affect directly the usability of the program, but our teacher said it can’t happen so... there is a way to make the both interfaces work togueter?
Something else I can say is that the both windows aren’t related, the only thing I need is that the both can work without interruptions
--
Steve (Gadget) Barnes
Any opinions in this message are my personal opinions and do not reflect
those of my employer.
---
This email has been checked for viruses by AVG.
Thank you for the feedback, i’ve tried something, almost work, but not too correctly,
First tried create a function that contains the creation of the wx.App, the frame and the mainloop, and other that makes the thread, works fine the first time i launch the
part of wx, but at the second time i get:
File “C:\Users\RED\PycharmProjects\NombreDeProyecto\venv\lib\site-packages\wx\core.py”, line 2096, in MainLoop
rv = wx.PyApp.MainLoop(self)
wxAssertionError: C++ assertion “wxThread::IsMain()” failed at …\src\msw\evtloop.cpp(182) in wxGUIEventLoop::Dispatch(): only the main thread can process Windows messages
Searching a little found that it probably it happens because I’m using a thread that aren’t the thread of the wx.app… here i’m a little bit off
Anyway, there is a fragment of the code that launch the part on wx.
self.boton4 = Button(self.ventanaPri, text="CONFIGURACION", width=13, height=1, command=self.lazador).place(x=102, y=0)
def CONF(self):
app = wx.App()
frame_usuarios = GestionGUIA()
app.MainLoop()
def lazador(self):
import threading
thread1 = threading.Thread(target= self.CONF, args = (), name = "tread1")
thread1.setDaemon(True)
thread1.start()
Probably a little example of how to avoid that and make the thread correctly could work for me
about the why i don't merge the rest to wx... i would do it if i could, but it's a work team, and i choose to do it on wx and they on
tk and i did not believe that little problem mattered until... yesterday... and probably... about my language, it's pretty bad,
my main one is spanish
<details class='elided'>
<summary title='Show trimmed content'>···</summary>
___________________________________
Manuel Pérez
And how to do it, I’m a little bit slow at this
Manuel Pérez wrote:
Thank you for the feedback, i've tried something, almost work, but not
too correctly,First tried create a function that contains the creation of the
wx.App, the frame and the mainloop, and other that makes the thread,
works fine the first time i launch the part of wx, but at the second
time i get:File
"C:\Users\RED\PycharmProjects\NombreDeProyecto\venv\lib\site-packages\wx\core.py",
line 2096, in MainLoop
rv = wx.PyApp.MainLoop(self)
wxAssertionError: C++ assertion "wxThread::IsMain()" failed at
..\..\src\msw\evtloop.cpp(182) in wxGUIEventLoop::Dispatch(): only the
main thread can process Windows messages
Yes, you didn't say that you wanted wx to come and go. That's not
possible During the wx initialization process, it captures the thread
ID, and from that point forward, that will always be considered the
"main thread". When you exit the main loop, you can't reinitialize wx.
If you can do what you need to do as a modal dialog, that should work,
because the modal dialog creates its own temporary message loop. But if
you need to do normal windows, then it's going to be more work. You
will need to have your wx thread launch once and once only, and keep the
app.MainLoop alive until the application exits. You can certainly
create other windows, but you'll have to use something like wx.CallAfter
to force them to be created in your wx thread.
···
--
Tim Roberts, timr@probo.com
Providenza & Boekelheide, Inc.