简体   繁体   English

GUI应用程序应该在驾驶员座位上使用哪个功能?

[英]Which Function Should be in the Driver's Seat on a GUI Application?

I am an electrical engineer building a Python application to interface with PSS/E (Power Systems Simulation for Engineers by PTI Siemens). 我是一位电气工程师,正在构建一个Python应用程序以与PSS / E(PTI Siemens的“工程师的电源系统仿真”)接口。 The way the code currently works, the program contains a main method which calls methods from two classes (in separate files) which I have written. 该程序当前包含的代码工作方式包含一个main方法,该方法从我编写的两个类(在单独的文件中)中调用方法。 Throughout the different steps of the program, the user interacts with it through a terminal (Enter file paths, press enter to continue, etc). 在程序的各个不同步骤中,用户都通过终端与之交互(输入文件路径,按Enter继续,等等)。

I am working on implementing a GUI with Tkinter. 我正在使用Tkinter实现GUI。 The user would browse to select several files, select certain options, then press 'Start'. 用户将浏览以选择多个文件,选择某些选项,然后按“开始”。 Then, the user would interact with the GUI at the different steps of the program, instead of typing into the terminal. 然后,用户将在程序的不同步骤与GUI交互,而不是键入终端。

What would be the philosophy used to implement a GUI into this program? 在此程序中实现GUI的原理是什么? I am thinking that on the one hand, I can have a file for the GUI, initiate the program from this file, then call the main method when the user pushes 'start'. 我在想,一方面,我可以为GUI创建一个文件,然后从该文件启动程序,然后在用户按下“开始”键时调用main方法。 The options/file paths from the user, would be passed to the main method as parameters. 来自用户的选项/文件路径将作为参数传递给main方法。 On the other hand, I'm thinking of integrating the GUI into my main method. 另一方面,我正在考虑将GUI集成到我的主要方法中。 Have a separate file with the class/methods for the Tkinter widgets, and call them from main as needed. 使用Tkinter小部件的类/方法创建一个单独的文件,并根据需要从main调用它们。 Which (if any) of these would be the best way to go, and why? 其中哪一个(如果有的话)是最好的选择,为什么? I also have a question about how to deal with Python 2.7 being 'retired' in January of 2020, since my code is dependent on version 2.7. 我也有一个关于如何处理2020年1月“退役” Python 2.7的问题,因为我的代码依赖于2.7版本。 I will ask this in another question to allow for some elaboration on this GUI question. 我将在另一个问题中提出这个问题,以便对这个GUI问题进行详细说明。 Thanks in advance for your input. 预先感谢您的输入。

While it is possible to write a GUI program as a straight port of a terminal program that works as you describe, with the main program driving the flow of interaction with the user, most GUI programs are written as a set of event handlers, also called callback functions. 虽然可以将GUI程序编写为按您描述的方式工作的终端程序的直接端口,但通过主程序来驱动与用户交互的流程,大多数GUI程序被编写为一组事件处理程序,也称为回调函数。 Because the event loop is calling back to you using the handlers you provide to it. 因为事件循环正在使用您提供给它的处理程序来回调您。

Usually the main program just declares your controls, binds them to handlers, and starts the event handling loop. 通常,主程序只是声明您的控件,将它们绑定到处理程序,然后启动事件处理循环。

There are various ways to organize such a program, and it depends a lot on your workflow. 组织此类程序的方式有很多种,这在很大程度上取决于您的工作流程。

But the event handling functions usually drive the overall logic, rather than the main program. 但是事件处理功能通常会驱动整体逻辑,而不是主程序。 This allows the user to interact with your program in a less linear way. 这允许用户以不太线性的方式与您的程序进行交互。

It is often useful to decouple the event handling logic and create a 'model' that represents the state of your program and logic unrelated to the GUI. 解耦事件处理逻辑并创建一个“模型”来表示程序状态和与GUI不相关的逻辑通常很有用。 Then the event handlers would call functions or methods of your model to change the state of the program. 然后,事件处理程序将调用模型的函数或方法以更改程序的状态。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在GUI应用程序中保存负载 - Save load in gui application 我想在 python 中编写一个名为 cont() 的函数,它发送一条消息“继续”并且不应该带任何参数 - i want to write a function in python named cont() which sends a message "continue" and which should take no argument PyQt Python GUI到Windows应用程序 - PyQt Python GUI to Windows application 我想为某些功能制作gui,但它不像我想要的那样,我正在使用python 2.7和Tkinter? - i wanna make gui for some function but it's not like what i want i am using python 2.7 and it's Tkinter? 以编程方式干净地关闭qt Gui应用程序 - Cleanly closing a qt Gui application application programatically 使用python创建运行时GUI。实际上我想在我的面板中从已打开的excel文件中提供复选框名称 - Run time GUI creation using python.Actually i want in my Panel the checkbox name should be given from an excel file which has been opened 一个函数,它知道从中调用它的包的名称 - A function that knows the name of the package from which it's been called 将文本从函数传递到gui - Passing text from a function to a gui 获取内置函数的方法名称,该方法名称作为参数传递并在函数体内调用 - get the inbuilt function's method name which is passed as an argument and call inside function body 我如何使用堆栈跟踪来告诉我应该为Python的try / except使用哪个异常 - How do I use stack trace to tell me which Exception I should use for Python's try/except
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM