Home > Enterprise >  Tkinter and ConfigParser
Tkinter and ConfigParser

Time:12-03

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.

enter image description here

enter image description here

enter image description here

enter image description here

enter image description here

CodePudding user response:

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)

CodePudding user response:

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)
  • Related