I'm trying to create a simple Tkinter app that will create folders within a specified directory. For instance, if you give it the prefix "folder_" and start = 1, end = 5, it will create folder_1, folder_2, folder_3, folder_4, folder_5. I can figure out this logic later, but right now I am having trouble understanding why whatever I type in the "start" Entry box is duplicated in the "end" Entry box. I created a test Entry box beside the Directory, and saw the same thing. What am I missing?
Any help would be much appreciated
Edit: The issue was with declaring variables startN and endN = int(). I changed them to = IntVar() and now when I type in the GUI entry box, I can put different values for start & end.
[![Screensnip of GUI][1]][1]from tkinter import *
from tkinter import ttk
import folderNames as folders
root = Tk()
root.title("Create Folders")
mainframe = ttk.Frame(root, padding="3 3 12 12")
mainframe.grid(column=0, row=0, sticky=(N, W, E, S))
root.columnconfigure(0, weight=1)
root.rowconfigure(0, weight=1)
directory = StringVar()
test = StringVar()
prefix = StringVar()
startN = int()
endN = int()
def calcFolders(*args):
try:
a = folders.getf(start_entry.get(), end_entry.get(), pref_entry.get())
return(a)
except ValueError:
pass
dir_entry = ttk.Entry(mainframe, width=7, textvariable = directory)
dir_entry.grid(column=2, row=1, sticky=(W, E))
test_entry = ttk.Entry(mainframe, width=7, textvariable = test)
test_entry.grid(column=4, row=1, sticky=(W, E))
pref_entry = ttk.Entry(mainframe, width=7, textvariable = prefix)
pref_entry.grid(column=2, row=2, sticky=(W, E))
start_entry = ttk.Entry(mainframe, width=7, textvariable = startN)
start_entry.grid(column=2, row=3, sticky=(W, E))
end_entry = ttk.Entry(mainframe, width=7, textvariable = endN)
end_entry.grid(column=4, row=3, sticky=(W, E))
ttk.Label(mainframe, text="Directory").grid(column=1, row=1, sticky=E)
ttk.Label(mainframe, text="Prefix").grid(column=1, row=2, sticky=E)
ttk.Label(mainframe, text="Start").grid(column=1, row=3, sticky=E)
ttk.Label(mainframe, text="End").grid(column=3, row=3, sticky=E)
ttk.Button(mainframe, text="CREATE", command=calcFolders()).grid(column=1, row=4, sticky=N)
for child in mainframe.winfo_children(): child.grid_configure(padx=5, pady=5)
dir_entry.focus()
root.bind('<Return>', calcFolders())
root.mainloop()