使用 Tkinter 围绕 python 脚本创建 gui
我有一个现有的 python 脚本,我想将它包装在 GUI 中。因为我已经安装了 tkinter,所以如果可能的话我想使用它。目前,我的脚本有很多地方使用 raw_input() 要求用户输入。我想用要求用户输入的模式弹出窗口或(最好)响应输入键的 Entry 对象来替换它们。
I have an existing python script and I want to wrap it in a GUI. Since I already have tkinter installed I would like to use it if possible. At the moment my script has many places where it asks for user input using raw_input(). I would like to replace these with either a modal pop-up asking for user input or (preferably) an Entry object which responds to the enter key.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
UI 工具包通常具有事件驱动模型,其中主循环位于工具包本身中。这可能与您当前的同步交互式模型(程序在等待输入时暂停)不同
最好是尝试重构您的程序并分解视图部分(查找模型-视图-控制设计模式)。之后,应该很容易将面向控制台的视图替换为基于 tkInter 的视图。
(这是我在没有具体问题的情况下所能得到的最具体的信息)
UI toolkits usually have an event-driven model where the main loop is in the toolkit itself. This is probably different from your current synchronous, interactive model (where the program just pauses while waiting for input)
The best would be to try to refactor your program and factor-out the view part (look up the model-view-control design pattern). After that, it should be easy to replace your console oriented view with an tkInter based one.
(that's as specific as I can get without a concrete question)