0

I have a small CLI app, with some "print" and "input" commands. I want to turn it into a basic GUI app (ideally with a windows .exe and a linux executable). This GUI app should display the text output (from print) in a window, and start a new window that prompts the user for some text (with an "enter" button) each time instead of running the usual "input" command.

I can see how I can do that in tkinter: define a new function "myinput" and use it instead of input everywhere. (The output will also require threads as there are delays in the functions and I don't want to wait for the end of the function to start displaying some text).

But I'm wondering if this hasn't been solved in a much better way by some other module. It seems like redefining input, or intercepting it's calls somehow, should be doable. Does this kind of "GUI-fy" command or module exist?

Note that a module that draws a console in a tkinter window then properly emulate the console just for that program would already be pretty good, thought not quite as nice as having pop-up windows for input; but again, I've seen some online python interpreters (like https://console.basthon.fr/) do a pop-up window just for inputs, so together with a drawn console this would be enough.

amstramgram
  • 71
  • 1
  • 7
  • 1
    I don't know if such a module exists, but you're better off writing your own program. It'll be easier to debug when you know what the code is doing (since you wrote it yourself), and you'll learn lots of useful GUI and event-driven-programming techniques that you wouldn't otherwise have learned if you had a module write your code for you. – Sylvester Kruin Apr 24 '22 at 20:49
  • [easygui](https://pypi.org/project/easygui/) – martineau Apr 24 '22 at 20:55
  • @martineau I thought that easygui was more of an alternative to tkinter, rather than allowing the kind of "interception" or "redefinition" of the built-in input command that I am looking for. Or am I missing something? – amstramgram Apr 24 '22 at 21:02
  • @SylvesterKruin I humbly disagree, which is why I was asking my initial question. I have already written this type of threaded program (in a different setting and language), and while writing it I realized it would be possible and useful to automatically "gui-fy" an existing program. One of the advantages would be that this could gui-fy an existing CLI program that is already compiled (by intercepting the calls to specific functions, or at least by redirecting standard input and output). It seems that this should be easier with python though, hence my question. – amstramgram Apr 24 '22 at 21:08
  • Well, without seeing the code, it's rather hard to say whether it'd be possible. You _could_ try searching on [GitHub](https://github.com) for something like this. But, depending of course on the organizational state of your code, it might not be that hard to manually switch it to a GUI. Again, without being able to _see_ your code, I can't tell for sure. – Sylvester Kruin Apr 24 '22 at 21:20
  • `easygui` won't display the text output from `print` in a window — although there are [ways to do that](https://stackoverflow.com/questions/18089506/writing-to-easygui-textbox-as-function-is-running/18091356#18091356). However it does provide simple ways to display new windows that prompt the user and wait for keyboard input. It doesn't do it automatically, but I strongly doubt something like what you want exists. My advice though, is to take the time to learn how to use `tkinter` and do [event-driven programming](https://en.wikipedia.org/wiki/Event-driven_programming). – martineau Apr 24 '22 at 23:58

0 Answers0