简体   繁体   English

Tkinter 和 ConfigParser

[英]Tkinter and ConfigParser

I am writing a small program where there are two entry widgets that load the path from the configuration file.Is it possible to insert a value into each entry widget (values in the config are in order)?I only managed to insert values into one widget.我正在编写一个小程序,其中有两个条目小部件从配置文件中加载路径。是否可以在每个条目小部件中插入一个值(配置中的值是有序的)?我只设法将值插入一个小部件。 And all the paths from the Input_311 config section are inserted there, but I only need one path in one widget. Input_311 配置部分的所有路径都插入到那里,但我只需要一个小部件中的一个路径。 I plan on making a lot more Entry Widgets, I would like to optimize the insertion process.我计划制作更多的条目小部件,我想优化插入过程。

在此处输入图像描述

在此处输入图像描述

在此处输入图像描述

在此处输入图像描述

在此处输入图像描述

Since you have used tkinter variables in those Entry widgets, I would suggest to create a list to store those tkinter variables, then use for loop to insert values into those Entry widgets as below:由于您在这些Entry小部件中使用了 tkinter 变量,我建议创建一个列表来存储这些 tkinter 变量,然后使用 for 循环将值插入到这些Entry小部件中,如下所示:

variables = [self.entry1Var1, self.entry2Var2, ...]

for var, path in zip(variables, CONFIG['Input_311'].values()):
    var.set(path)

With all advices, answer for my question is:有了所有建议,我的问题的答案是:

variables = [self.entry_1, self.entry_2]
for var, path in zip(variables, CONFIG['Input_311'].values()):
    var.insert(0, path)

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM