I am New to use Tkinter
.I want to create multiple checkbox from loop.I refer Tkinter checkboxes created in loop but i don't understand it. I want to display all files as a checkbox located in a directory.
Help me and tell me what i need to change ?
Code:
from tkinter import filedialog,Checkbutton
import tkinter,os
window = tkinter.Tk()
def browse():
filez = filedialog.askdirectory(parent=window,title='Choose a file')#I choose a directory
ent1.insert(20,filez)#insert the path of directory to text box
dirs = os.listdir(filez)#gives all files of direcory
for file in dirs:
print(file)#Getting all files
var = tkinter.IntVar()
c = tkinter.Checkbutton(window,text=file,variable=var)#Create files to checkox
c.place(x=0,y=100)
window.title("First Gui")
window.geometry("400x400")
window.wm_iconbitmap("path of icon")
lbl = tkinter.Label(window,text="path")
lbl.place(x=0,y=60)
ent1 = tkinter.Entry(window)
ent1.place(x=80,y=60)
btn1 = tkinter.Button(window,text="Set Path",command=browse)
btn1.place(x=210,y=57)
window.mainloop()
After click on button set path i want to to display all files of directory as a checkbox using browse function
Aucun commentaire:
Enregistrer un commentaire