I am doing the O'reilly School of Technology course and the current topic deals with Tkinter. It gave me the idea to write this application.
The idea is to transfer files to various ftp sites. If I set a default master password, then the password should be used for all sites. If I click the add/remove button it should add/remove a line for the next sites details. Ideaily the remove button should remove the current site from the list, right now it removes the last site(or trys to anyway). Not sure how to keep track of that.
I am having problems with the following:
1) Having the master passward update all site password entries
2) The add/remove looses count and dosen't always remove the sites(say if I add 4+ entries)
I have no idea what's wrong, any help would be appreciated.
#!/usr/bin/env python
from Tkinter import *
class Application(Frame):
def __init__(self, master=None):
Frame.__init__(self, master)
self.grid(sticky=N+S+E+W)
self.master.rowconfigure(0, weight=1)
self.master.columnconfigure(0, weight=1)
self.master.title('Bulk FTP Updater')
self.createShell()
self.toggle_pass = 1
def createShell(self):
self.e_master_var = StringVar()
self.use_master_p = IntVar()
self.l_master = Label(self, text='Master Password:')
self.e_master = Entry(self, textvariable=self.e_master_var)
self.c_master = Checkbutton(self, textvariable=self.use_master_p,
command=self.use_master_pass)
self.l2_master = Label(self, text='Set as default')
self.blank = Label(self, text='', pady=20)
self.l_master.grid(row=0, column=0, sticky=W)
self.e_master.grid(row=0, column=1, sticky=W)
self.l2_master.grid(row=1, column=0, sticky=E)
self.c_master.grid(row=1, column=1, sticky=W)
self.blank.grid(row=2, column=0)
self.r = 3
self.createSite(self.r)
def use_master_pass(self):
password = self.e_master_var.get()
if self.toggle_pass:
for r in range(3, self.r+1):
self.v_pass.set(password)
self.toggle_pass = 0
else:
for r in range(3, self.r+1):
self.v_pass.set('')
self.toggle_pass = 1
def createSite(self, r):
self.l_host = Label(self, text='Site:', padx=10)
self.l_user = Label(self, text='User:', padx=10)
self.l_pass = Label(self, text='Password:', padx=10)
self.v_host = StringVar()
self.v_user = StringVar()
self.v_pass = StringVar()
self.e_host = Entry(self, textvariable=self.v_host)
self.e_user = Entry(self, textvariable=self.v_user)
self.e_pass = Entry(self, textvariable=self.v_pass)
self.b_add = Button(self, text='Add', command=self.add, padx=10)
self.b_del = Button(self, text='Remove', command=self.remove, padx=10)
self.l_host.grid(row=r, column=0, sticky=E)
self.e_host.grid(row=r, column=1, sticky=E)
self.l_user.grid(row=r, column=2, sticky=E)
self.e_user.grid(row=r, column=3, sticky=E)
self.l_pass.grid(row=r, column=4, sticky=E)
self.e_pass.grid(row=r, column=5, sticky=E)
self.b_add.grid(row=r, column=6, sticky=E)
self.b_del.grid(row=r, column=7, sticky=E)
print 'createSite:', r
def add(self):
self.r = self.r + 1
self.createSite(self.r)
print 'add:', self.r
def remove(self):
if self.r > 3:
self.r = self.r - 1
self.l_host.destroy()
self.l_user.destroy()
self.l_pass.destroy()
self.e_host.destroy()
self.e_user.destroy()
self.e_pass.destroy()
self.b_add.destroy()
self.b_del.destroy()
elif self.r < 3:
self.r = 3
print 'remove:', self.r
root = Tk()
app = Application(master=root)
app.mainloop()