0

I spent the last hours trying to get to know wxPython, because I want to write a GUI program. I found some tutorials on that (not too many), but all of them just explain how to add yet another kind of widget, down to fancy things like LED number outputs and mouse gestures (this one e.g. takes it quite far: Another Tutorial). But everything I could find so far does nothing more than create a static GUI, waiting for the user to do something, then execute some handlers and wait again. It took me a while to even find out that wx.App takes a part in all of that, and that you can subclass it.

I want to write a program, that does things without input! The GUI is supposed to be a client that logs in on a server, and when the server sends something, I want the GUI to show what happened. I could not find a single tutorial even mentioning, that such programs exist. How can I write such a thing? How do they integrate with wxpython?

Do I need to span another thread? Is there a way to hook into the MainLoop and have some code executed periodically, that checks for change and then updates some of those fancy GUI things? And is there any page that teaches you, how to do this?

3
  • of course, just after asking someone, you find a clue: github.com/wxWidgets/wxPython/blob/master/samples/mainloop/… - but still, I would love to get some inside from gui guys Commented Sep 10, 2013 at 16:46
  • I would start with a wx.TextCtrl. Find the property or method that allows you to write a value into the control to change the text. Commented Sep 10, 2013 at 16:48
  • @RobertHarvey The process of changing a value is not what I have a problem with. My problem is integrating the main loop of my program (what it does outside interacting with me) with the GUI. Commented Sep 10, 2013 at 16:57

1 Answer 1

1

First of all, you should figure out how to do what you want WITHOUT a GUI. In this case, you'll need to figure out how to login to a server. You'll probably need to use something like paramiko for that. See http://www.lag.net/paramiko/

Once you've got that figured out, then you can add it to your GUI. Probably in a button handler so when the user presses a button, it pops up a dialog asking for a user name and password to pass to paramiko to login to the server.

If the server query takes a long time to execute (like say you're querying a database for a huge set of data), then you'll want to run the query in a separate thread. Why? Because that query will block the GUI's main loop and make your app freeze until it finishes. See the following articles for information on wxPython and threads:

I wrote up a tutorial on making wxPython talk to a socket server, so you might find that useful: http://www.blog.pythonlibrary.org/2013/06/27/wxpython-how-to-communicate-with-your-gui-via-sockets/

I also have an article on how to make an image viewer, and do CRUD ops to a database on there.

Sign up to request clarification or add additional context in comments.

1 Comment

I know pretty well what I want to do without a GUI. In fact, what I'm trying to do right now, I have already achieved twice, writing a program using pygame. There I had control over the main loop and could do what I want, even without the need of threads. I will take a closer look at your links, the part with sending a message to a running GUI application from a command line program is not so different from what I try to do.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.