简体   繁体   中英

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. 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:

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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