Re: confused about classes and tkinter object design

2008-11-27 Thread marc wyburn
On Nov 26, 12:09 pm, Bruno Desthuilliers bruno.
[EMAIL PROTECTED] wrote:
 marc wyburn a écrit :

  Hi,

  I've created my firstTkinterGUI class which consists of some buttons
  that trigger functions.  I have also created a
  tkFileDialog.askdirectory control to local a root folder for log
  files.

  I have several file paths that depend on the value of
  tkFileDialog.askdirectory should I create an object that inherits this
  value or can I point functions at the GUI class?

  I am creating thetkinterGUI instance using;

  if __name__ == __main__:
      GUI = AuditorGUI()

 Note that at this point, the AuditorGUI class is not yet defined, so you
 should get a NameError.



      GUI.mainloop()

  class AuditorGUI(Frame):

 I assume you have all necessary imports in your real code...





      def __init__(self):
          Frame.__init__(self)
          self.pack(expand = YES, fill = BOTH)

  ##      Create GUI objects

          self.currentdir = StringVar()
          self.currentdir.set(os.getcwd())

          self.logdir = Button(self, text=Choose Data
  directory,command=self.choose_dir)
          self.logdir.grid(row=1,column=0,sticky='nsew',pady=20,padx=20)

          self.labeldirpath = Label(self, textvariable=self.currentdir)

      def choose_dir(self):
          dirname = tkFileDialog.askdirectory
  (parent=self,initialdir=self.currentdir.get(),title='Please select a
  directory')
          if len(dirname )  0:
              self.currentdir.set(dirname)

  I think I have created an instance of the AuditorGUI class called GUI
  so should be able to access the path using GUI.currentdir but this
  doesn't work.

 does not work is (almost) the less possible usefull description of a
 problem. What happens exactly ? Do you have a traceback ? If so, please
 post the full traceback and error message. Else, please explain what
 result you get. And if possible, post minimal *working* code reproducing
 the problem.

  I'm still struggling with classes so not sure whether my problem is
 tkinterrelated or not.

 Minus the couple problems above (ie: trying to instanciate a
 non-yet-existing class, and lack of necessary imports), it seems correct
 - at least wrt/ class definition and instanciation.- Hide quoted text -

 - Show quoted text -

thanks for your help.  I'm not creating the instances properly.
Everything works as expected if I merge everything into the class.
Time to get the manual out again.  Thanks for pointing me in the right
direction. MW
--
http://mail.python.org/mailman/listinfo/python-list


Re: confused about classes and tkinter object design

2008-11-26 Thread Bruno Desthuilliers

marc wyburn a écrit :

Hi,

I've created my first Tkinter GUI class which consists of some buttons
that trigger functions.  I have also created a
tkFileDialog.askdirectory control to local a root folder for log
files.

I have several file paths that depend on the value of
tkFileDialog.askdirectory should I create an object that inherits this
value or can I point functions at the GUI class?

I am creating the tkinter GUI instance using;

if __name__ == __main__:
GUI = AuditorGUI()


Note that at this point, the AuditorGUI class is not yet defined, so you 
should get a NameError.



GUI.mainloop()



class AuditorGUI(Frame):


I assume you have all necessary imports in your real code...


def __init__(self):
Frame.__init__(self)
self.pack(expand = YES, fill = BOTH)

##  Create GUI objects

self.currentdir = StringVar()
self.currentdir.set(os.getcwd())

self.logdir = Button(self, text=Choose Data
directory,command=self.choose_dir)
self.logdir.grid(row=1,column=0,sticky='nsew',pady=20,padx=20)

self.labeldirpath = Label(self, textvariable=self.currentdir)

def choose_dir(self):
dirname = tkFileDialog.askdirectory
(parent=self,initialdir=self.currentdir.get(),title='Please select a
directory')
if len(dirname )  0:
self.currentdir.set(dirname)

I think I have created an instance of the AuditorGUI class called GUI
so should be able to access the path using GUI.currentdir but this
doesn't work.


does not work is (almost) the less possible usefull description of a 
problem. What happens exactly ? Do you have a traceback ? If so, please 
post the full traceback and error message. Else, please explain what 
result you get. And if possible, post minimal *working* code reproducing 
the problem.



I'm still struggling with classes so not sure whether my problem is
tkinter related or not.


Minus the couple problems above (ie: trying to instanciate a 
non-yet-existing class, and lack of necessary imports), it seems correct 
- at least wrt/ class definition and instanciation.

--
http://mail.python.org/mailman/listinfo/python-list


confused about classes and tkinter object design

2008-11-25 Thread marc wyburn
Hi,

I've created my first Tkinter GUI class which consists of some buttons
that trigger functions.  I have also created a
tkFileDialog.askdirectory control to local a root folder for log
files.

I have several file paths that depend on the value of
tkFileDialog.askdirectory should I create an object that inherits this
value or can I point functions at the GUI class?

I am creating the tkinter GUI instance using;

if __name__ == __main__:
GUI = AuditorGUI()
GUI.mainloop()

class AuditorGUI(Frame):
def __init__(self):
Frame.__init__(self)
self.pack(expand = YES, fill = BOTH)

##  Create GUI objects

self.currentdir = StringVar()
self.currentdir.set(os.getcwd())

self.logdir = Button(self, text=Choose Data
directory,command=self.choose_dir)
self.logdir.grid(row=1,column=0,sticky='nsew',pady=20,padx=20)

self.labeldirpath = Label(self, textvariable=self.currentdir)

def choose_dir(self):
dirname = tkFileDialog.askdirectory
(parent=self,initialdir=self.currentdir.get(),title='Please select a
directory')
if len(dirname )  0:
self.currentdir.set(dirname)

I think I have created an instance of the AuditorGUI class called GUI
so should be able to access the path using GUI.currentdir but this
doesn't work.

I'm still struggling with classes so not sure whether my problem is
tkinter related or not.

Thanks, MW

--
http://mail.python.org/mailman/listinfo/python-list


Re: confused about classes and tkinter object design

2008-11-25 Thread r
On Nov 25, 10:38 am, marc wyburn [EMAIL PROTECTED] wrote:
 Hi,

 I've created my first Tkinter GUI class which consists of some buttons
 that trigger functions.  I have also created a
 tkFileDialog.askdirectory control to local a root folder for log
 files.

 I have several file paths that depend on the value of
 tkFileDialog.askdirectory should I create an object that inherits this
 value or can I point functions at the GUI class?

 I am creating the tkinter GUI instance using;

 if __name__ == __main__:
     GUI = AuditorGUI()
     GUI.mainloop()

 class AuditorGUI(Frame):
     def __init__(self):
         Frame.__init__(self)
         self.pack(expand = YES, fill = BOTH)

 ##      Create GUI objects

         self.currentdir = StringVar()
         self.currentdir.set(os.getcwd())

         self.logdir = Button(self, text=Choose Data
 directory,command=self.choose_dir)
         self.logdir.grid(row=1,column=0,sticky='nsew',pady=20,padx=20)

         self.labeldirpath = Label(self, textvariable=self.currentdir)

     def choose_dir(self):
         dirname = tkFileDialog.askdirectory
 (parent=self,initialdir=self.currentdir.get(),title='Please select a
 directory')
         if len(dirname )  0:
             self.currentdir.set(dirname)

 I think I have created an instance of the AuditorGUI class called GUI
 so should be able to access the path using GUI.currentdir but this
 doesn't work.

 I'm still struggling with classes so not sure whether my problem is
 tkinter related or not.

 Thanks, MW

--
http://mail.python.org/mailman/listinfo/python-list


Re: confused about classes and tkinter object design

2008-11-25 Thread r
On Nov 25, 10:38 am, marc wyburn [EMAIL PROTECTED] wrote:
 Hi,

 I've created my first Tkinter GUI class which consists of some buttons
 that trigger functions.  I have also created a
 tkFileDialog.askdirectory control to local a root folder for log
 files.

 I have several file paths that depend on the value of
 tkFileDialog.askdirectory should I create an object that inherits this
 value or can I point functions at the GUI class?

 I am creating the tkinter GUI instance using;

 if __name__ == __main__:
     GUI = AuditorGUI()
     GUI.mainloop()

 class AuditorGUI(Frame):
     def __init__(self):
         Frame.__init__(self)
         self.pack(expand = YES, fill = BOTH)

 ##      Create GUI objects

         self.currentdir = StringVar()
         self.currentdir.set(os.getcwd())

         self.logdir = Button(self, text=Choose Data
 directory,command=self.choose_dir)
         self.logdir.grid(row=1,column=0,sticky='nsew',pady=20,padx=20)

         self.labeldirpath = Label(self, textvariable=self.currentdir)

     def choose_dir(self):
         dirname = tkFileDialog.askdirectory
 (parent=self,initialdir=self.currentdir.get(),title='Please select a
 directory')
         if len(dirname )  0:
             self.currentdir.set(dirname)

 I think I have created an instance of the AuditorGUI class called GUI
 so should be able to access the path using GUI.currentdir but this
 doesn't work.

 I'm still struggling with classes so not sure whether my problem is
 tkinter related or not.

 Thanks, MW

first off i would use a different instance variable besides GUI.
Could be AG or auditorgui.
Also the conditional if len(dirname )  0: could simply be if
dirname:
When you ask for the attribute currentdir are you asking as
GUI.currentdir.get() or GUI.currentdir???
only the second will work with a TKVAR, but there is really no need to
use a TKVAR here. I would simply do:

self.currentdir = None

then you could say:
if GUI.currentdir:
do this()



--
http://mail.python.org/mailman/listinfo/python-list


Re: confused about classes and tkinter object design

2008-11-25 Thread r
On Nov 25, 2:31 pm, r [EMAIL PROTECTED] wrote:
 On Nov 25, 10:38 am, marc wyburn [EMAIL PROTECTED] wrote:



  Hi,

  I've created my first Tkinter GUI class which consists of some buttons
  that trigger functions.  I have also created a
  tkFileDialog.askdirectory control to local a root folder for log
  files.

  I have several file paths that depend on the value of
  tkFileDialog.askdirectory should I create an object that inherits this
  value or can I point functions at the GUI class?

  I am creating the tkinter GUI instance using;

  if __name__ == __main__:
      GUI = AuditorGUI()
      GUI.mainloop()

  class AuditorGUI(Frame):
      def __init__(self):
          Frame.__init__(self)
          self.pack(expand = YES, fill = BOTH)

  ##      Create GUI objects

          self.currentdir = StringVar()
          self.currentdir.set(os.getcwd())

          self.logdir = Button(self, text=Choose Data
  directory,command=self.choose_dir)
          self.logdir.grid(row=1,column=0,sticky='nsew',pady=20,padx=20)

          self.labeldirpath = Label(self, textvariable=self.currentdir)

      def choose_dir(self):
          dirname = tkFileDialog.askdirectory
  (parent=self,initialdir=self.currentdir.get(),title='Please select a
  directory')
          if len(dirname )  0:
              self.currentdir.set(dirname)

  I think I have created an instance of the AuditorGUI class called GUI
  so should be able to access the path using GUI.currentdir but this
  doesn't work.

  I'm still struggling with classes so not sure whether my problem is
  tkinter related or not.

  Thanks, MW

 first off i would use a different instance variable besides GUI.
 Could be AG or auditorgui.
 Also the conditional if len(dirname )  0: could simply be if
 dirname:
 When you ask for the attribute currentdir are you asking as
 GUI.currentdir.get() or GUI.currentdir???
 only the second will work with a TKVAR, but there is really no need to
 use a TKVAR here. I would simply do:

 self.currentdir = None

 then you could say:
 if GUI.currentdir:
     do this()

 When you ask for the attribute currentdir are you asking as
 GUI.currentdir.get() or GUI.currentdir???
 only the second will work with a TKVAR

correction:
only GUI.currentdir.get() will work with TKVAR
my bad:(
--
http://mail.python.org/mailman/listinfo/python-list