python - Python 在其他模块中更新 scrolledtxt
问题描述
我的代码分为 2 个模块。一个是子(GUI-tkinter)模块,另一个是主(主功能模块)。
子模块(GUI)
import main
import tkinter as tk
from tkinter import filedialog
from tkinter import scrolledtext
class GUI():
def __init__(self, master):
# create Window and widgets ...
self.bt_gen = tk.Button(master, text="Generation", command=lambda: self.runGenCode())
self.bt_gen.grid(row=3, column=1, padx=5, pady=5, sticky='nsew') # button : generation
def setScrollTxt(self, text):
self.txt_status.insert(tk.INSERT, text)
self.txt_status.see(tk.END)
def clearScrollTxt(self):
self.txt_status.delete('1.0', tk.END)
def runGenCode(self):
main(self, self.dir_input, self.dir_output)
self.setScrollTxt("\nCode Generated Successfully!!!\n")
root = tk.Tk() # create window
app = GUI(root) # create object
root.mainloop()
主模块(主函数)
def main(self, input, output):
# function : import data from excel
self.setScrollTxt("1/4. Import Data : Done!\n")
# function : pre-process data
self.setScrollTxt("2/4. Data Pre-Process : Done!\n")
with open(filename_output + ".h", "w") as fo:
# function : write file
self.setScrollTxt("3/4. Export Data to .h file : Done!\n")
with open(filename_output + ".c", "w") as fo:
# function : write file
self.setScrollTxt("4/4. Export Data to .c file : Done!\n")
if __name__ == "__main__":
main()
这是我的代码(简单版)
我的问题是'main'函数中没有更新scrolledtxt。每一步完成后,在'main'模块中调用函数'setScrollTxt'。但 scrolledtxt 没有改变。只有在完成 'main' 模块并执行 'root.mainloop' 之后,才会更新 scrolledtxt。
我怎么解决这个问题?
解决方案
推荐阅读
- python - 在 AWS 中上传 word2vec 模型会出错
- nuxt.js - 在 Nuxt 应用程序的布局中访问 ctx 属性
- python - 有没有办法将色调仅应用于 seaborn 中 PairGrid 的下部
- performance - 什么时候在 Velocity 中评估字符串?
- abap - 将键值映射到结构
- spring-boot - SpringBoot Spring Security 不能将给定的过滤器仅应用于一个路径
- clojure - 如何将 .edn 文件包含为另一个“父”.edn 文件的子集,例如 .xml 文件中的“包含路径”元素?
- shopify - 使用礼品卡在 Shopify 中购买产品时如何禁用其他付款方式?
- asp.net - 如何在 NServiceBus 路由中给出另一个解决方案的路由?
- spring-boot - 获取并解码来自 RestTemplate spring boot 的响应