Let's say I have a text file which contains 10 numbers
I have written a code to select and open the file, the default window shows a pushbutton to select it and an empty combobox
I would like to fill the combobox with values from the file when it is opened but without close the window
from tkinter.filedialog import askopenfilename
import os
import tkinter as tk
from tkinter import ttk
class Application(tk.Tk):
def __init__(self):
tk.Tk.__init__(self)
ButtonSelect_File = tk.Button(self, text='Select file', command=self.displayPath)
ButtonSelect_File.grid(row=1, column=0)
self._File = tk.StringVar(self)
self._File.set('')
label_File = tk.Label(self, textvariable=self._File)
label_File.grid(row=1, column=1)
self.combobox = ttk.Combobox(self, values=[])
self.combobox.grid(row=2, column=0)
def displayPath(self):
self.File = askopenfilename()
self.directory = os.path.split(self.File)[0]
self._File.set(self.File)
def readFile(self, file):
read = open(file, "r")
values = [i for i in read]
### HOW TO ADD THESE VALUES TO THE COMBOBOX ####
if __name__ == "__main__":
obj = Application()
obj.mainloop()
obj.readFile(obj.File)
Could someone tell me how to do that ?