[Tutor] A better way to do it.

Aztech Guy aztech1200 at yahoo.com
Sat Dec 25 16:51:09 CET 2004


Hi Jacob,

Since your class derives from Frame, check Frame for
methods to change the title. If that doesn't work, try
this: Tkinter is based on Tk (which works with TCL).
So try posting your question on comp.lang.tcl. You can
do this via Google Groups: groups.google.com. You need
to register once, its free.

HTH
Az
--- "Jacob S." <keridee at jayco.net> wrote:

> Okay, here's the code.
> 
> I am completely open to suggestions as this is my
> first dabbling in Tk.
> Please look over it when you have time.
> 
> I have a couple of questions.
> 1) How do I change the title of the window?
> 2) Why does a window pop up saying something like
> error, the memory could
> not be "read". I'm running
> Windows XP, the script window disappears, and
> everything, just this message
> pops up.
> 
> 
> Jacob Schmidt
> 
>
----------------------------------------------------------------------------
> -
> from Tkinter import *
> import tkMessageBox
> import os
> from filecmp import cmpfiles
> 
> class Copying:
>     def __init__(self,action,var,err):
>         self.action = action
>         self.pri = var
>         self.err = err
> 
>         self.j = os.path.join
>         self.r = os.path.isdir
>         self.e = os.path.isfile
> 
>        
>
####################################################################
>         #  These are the default values for the
> directories. To make it
> simpler you could... ##
>         ## pseudo
>         ##  self.usbdrive = remote folder
>         ## self.desktop = localer folder
>        
>
####################################################################
>         dirlist = os.listdir("c:\\")
>         if 'Jacob Laptop' in dirlist:
>             self.usbdrive = 'E:\\Working Python
> Programs'
>             self.desktop = 'C:\\documents and
> settings\\jacob\\desktop\\Working Python Programs'
>         elif 'Home Computer' in dirlist:
>             self.usbdrive = 'F:\\Working Python
> Programs'
>             self.desktop = 'C:\\documents and
> settings\\owner\\desktop\\Working Python Programs'
>         elif 'Sissy Computer' in dirlist:
>             self.usbdrive = '' ## Need to fill in
>             self.desktop = ''  ## Need to fill in
>         elif 'Michael Laptop' in dirlist:
>             self.usbdrive = 'E:\\Working Python
> Programs'
>             self.desktop = 'C:\\documents and
> settings\\michael\\desktop\\Working Python Programs'
>         elif 'Office Computer' in dirlist:
>             self.usbdrive = 'D:\\Working Python
> Programs'
>             self.desktop =
> 'C:\\windows\\desktop\\Working Python Programs'
>         elif 'School Auction Laptop' in dirlist:
>             self.usbdrive = '' ## Need to fill in
>             self.desktop =
> 'C:\\windows\\desktop\\Working Python Programs'
>         else:
>             print 'Hey you need to put a folder in
> this computer!. '
>             print '''Folders include:
>             Jacob Laptop
>             Home Computer
>             Sissy Computer
>             Michael Laptop
>             Office Computer
>             School Auction Laptop
>             '''
>             folder = raw_input('Which computer is
> this? ')
>             folder = "C:\\"+folder
>             os.mkdir(folder)
>             self.usbdrive = raw_input('What is the
> usb drive on this
> computer? ')
>             self.desktop = raw_input('What is the
> desktop on this computer?
> ')
> 
>         #
> ################################################# #
>         if not os.path.exists(self.desktop):
>             os.mkdir(self.desktop)
>         m =
> {'receiving':self.receiving,'sending':self.sending}
>         m[self.action]()
> 
> 
>     def copyfile(self,src,des):
>         x = open(src,'rb').read()
>         y = open(des,'wb')
>         y.write(x)
>         y.close()
> 
> 
>     def receiving(self):
>         chiplist = os.listdir(self.usbdrive)
>         pclist = os.listdir(self.desktop)
>         filechange =
> cmpfiles(self.usbdrive,self.desktop,chiplist)[1]
>         tot = 0
>         for x in chiplist:
>             if x not in pclist:
>                 filechange.append(x)
>         for x in filechange:
>             fullname = self.j(self.usbdrive,x)
>             if self.e(fullname):
>                
> self.copyfile(fullname,self.j(self.desktop, x))
>                 self.pri.set("Copying %s." % x)
>                 self.err.insert(END,"%s copied from
> chip to computer.\n" %
> x)
>                 tot = tot + 1
>             elif self.r(fullname):
>                 self.err.insert(END,"%s is a
> directory. It has not been
> copied.\n" % fullname)
>         self.err.insert(END,"%s file(s)
> copied.\n"%tot)
>         self.pri.set("")
>         pclist.sort()
>         chiplist.sort()
>         newlist = [x for x in pclist if x not in
> chiplist]
>         for x in newlist:
>             if
> tkMessageBox.askokcancel('Delete?',"Do you wish to
> delete %s?
> " % x):
>                 filename = self.j(self.desktop, x)
>                 if self.e(filename):
>                     os.remove(filename)
>                     self.err.insert(END,"%s has been
> removed from your
> chip.\n"%x)
>                 elif self.r(filename):
>                     os.rmdir(filename)
>                     self.err.insert(END,"%s has been
> removed from your
> chip.\n"%x)
>             else:
>                 self.err.insert(END,"Did not remove
> %s\n"%x)
> 
>     def sending(self):
>         pclist = os.listdir(self.desktop)
>         chiplist = os.listdir(self.usbdrive)
>         filechange =
> cmpfiles(self.desktop,self.usbdrive,pclist)[1]
>         tot = 0
>         for x in pclist:
>             if x not in chiplist:
>                 filechange.append(x)
>         for x in filechange:
>             fullname = self.j(self.desktop,x)
>             if self.e(fullname):
>                
> self.copyfile(fullname,self.j(self.usbdrive,x))
>                 self.pri.set("Copying %s. " % x)
>                 self.err.insert(END,"%s copied from
> computer to chip.\n" %
> x)
>                 tot = tot + 1
>             elif self.r(fullname):
>                 self.err.insert(END,"%s is a
> directory. It has not been
> copied.\n" % x)
>         self.err.insert(END,"%s file(s)
> copied.\n"%tot)
>         self.pri.set("")
>         chiplist.sort()
>         pclist.sort()
>         newlist = [x for x in chiplist if x not in
> pclist]
>         for x in newlist:
>             if
> tkMessageBox.askokcancel('Delete?',"Do you wish to
> delete %s?
> " % x):
>                 filename = self.j(self.usbdrive, x)
>                 if self.e(filename):
>                     os.remove(filename)
>                     self.err.insert(END,"%s has been
> removed from your
> 
=== message truncated ===



		
__________________________________ 
Do you Yahoo!? 
Yahoo! Mail - now with 250MB free storage. Learn more.
http://info.mail.yahoo.com/mail_250


More information about the Tutor mailing list