How can I create a GUI on top of a Python APP so it can do either GUI or CLI?

前端 未结 4 1032
北海茫月
北海茫月 2021-01-01 07:17

I am trying to write an app in python to control a motor using serial. This all works in a CLI situation fine and is generally stable. but I was wondering how simple it was

4条回答
  •  时光说笑
    2021-01-01 07:48

    It depends on which kind of interaction you want.

    If you want a real GUI you can use the humble dialog pattern to decouple the GUI stuff from the program logic, and use a text "GUI" to handle the CLI. This also has the nice side-effect that big parts of the GUI get programmable testable.

    Another way is to assign sys.stdin and sys.stout with own objects, which redirect your programs IO to the GUI (this does not work with non-python libraries). This means that you have fewer interaction possibilities in the GUI, but much less programming effort.

提交回复
热议问题