confused about classes and tkinter object design

r rt8396 at gmail.com
Tue Nov 25 15:23:27 EST 2008


On Nov 25, 10:38 am, marc wyburn <marc.wyb... at googlemail.com> 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




More information about the Python-list mailing list