我编写了一些主要用于控制台的代码,但被要求为其创建一个简单的 GUI 以方便使用。在其中,我正在使用小部件设置主框架,并使用小部件命令调用我导入的函数。但是,导入的函数和模块都写入输出控制台。是否有一种方法可以在子进程运行时返回要在 GUI 中更新的输出字符串/控制台输出?
示例脚本:
import Tkinter as *
import myModule1
class MyGUI(Frame):
def __init__(self):
# Initialization stuff.
self.initGUI()
def initGUI(self):
self.downloadButton = Button(text="Download data.")
self.downloadButton["command"] = myModule1.function
# This function from myModule1 will constantly print to the console as the process is performed - is there any way to have this displayed in the GUI as a ScrollBar?
.....
或者,有没有办法在进程运行时显示一个对话框窗口?我问是因为我在 myModule1 及其子模块中嵌入了很多打印语句,这些语句将正在发生的事情返回到控制台。最好为用户显示那些 GUI 正在工作的用户,我将其转换为 .exe 以方便使用它的用户使用。
谢谢你。
编辑:一个myModule1.function
看起来像的例子:
import otherModule
def function1():
log = otherModule.function2():
if log == True:
print "Function 2 worked."
elif log == False:
print "Function 2 did not work."
但是,function2
在otherModule
执行计算时打印到控制台。此处未明确显示,但控制台输出本质上是一系列计算,然后是上面显示的示例 if/elif 子句。