3 beginner questions!

Ali Dada afd00 at aub.edu.lb
Wed May 7 19:16:22 EDT 2003


thanks all for your ideas on PyQt: they got me going!!

but the problem with Tkinter (question 2) is still not solved. i
tested Rene's code but it still didn't work. and by the way, i tried
to run a PyQt-generated window from a Tkinter window but the former
messes up the latter and rendered it unusable. any ideas on mixing the
two libraries in my application or is it an unrecommended approach??
thanks again for your help!!

Rune Hansen <rune.hansen at viventus.no> wrote in message news:<b9b482$8or$1 at services.kq.no>...
> Ali Dada wrote:
> > hi all:
> > 
> > second question (Tkinter and Pmw)
> > 
> > i wrote the file below, called ScrolledListBox.py, and it works
> > fine when run directly from the terminal (ie it brings up a ScrolledListBox with
> > three entries so that when you select any of them it performs it function
> > properly, writing 'hi' to stdout)
> > 
> > 
> > #!/usr/bin/env python
> > from Tkinter import *
> > import Pmw
> > 
> > class ImageSelection(Frame ):
> >   
> >  def __init__( self):
> >   root = Tk()
> >   Frame.__init__( self )
> >   Pmw.initialise()
> >   self.pack( expand = YES, fill=BOTH)
> >   self.suites=['a', 'b', 'c']
> >   self.listBox = Pmw.ScrolledListBox( root, items = self.suites, listbox_height
> > = 5, vscrollmode = "static", selectioncommand  = self.switchSuite)
> >   self.listBox.pack( side = LEFT, expand = YES, fill= BOTH, padx = 5, pady=5)
> >   
> >  def switchSuite(self):
> >   print 'hi'
> >   
> > def main():
> >  ImageSelection().mainloop()
> >  
> >  
> > if __name__ == "__main__":
> >  ImageSelection().mainloop()
> > 
> > 
> > now the problem comes. i need to call the  above from a new file called
> > Index.py, shown below. Index.py imports ScrolledListBox and makes a Button that
> > calls ScrolledListBox. surprisingly (for me at least) the three entries in the
> > ListBox don't perform as expected. 
> > 
> > 
> > 
> > #!/usr/bin/env python
> > from Tkinter import *
> > import ScrolledListBox
> > 
> > class Index(Frame):
> >  def __init__(self, parent=None):
> >   
> >   Frame.__init__(self, parent)
> >   Button(self, text='Regression', command=ScrolledListBox.main).pack(side=TOP,
> > fill=BOTH)
> >   
> >  
> > if __name__ == '__main__':
> >  i = Index()
> >  i.pack()
> >  i.mainloop()
> > 
> Yet again a question of inheritance. Personally I would have written it 
> along these lines:
> --
> --ScrolledListBox.py
> #!/usr/bin/env python
> from Tkinter import *
> import Pmw
> 
> class ImageSelection(Frame ):
>      def __init__( self):
>          Frame.__init__( self )
>          root = Tk()
>          Pmw.initialise()
> 
>          self.pack( expand = YES, fill=BOTH)
>          self.suites=['a', 'b', 'c']
>          self.listBox = Pmw.ScrolledListBox( root, items = self.suites, 
> listbox_height= 5, vscrollmode = "static", selectioncommand  = 
> self.switchSuite)
>          self.listBox.pack( side = LEFT, expand = YES, fill= BOTH, padx 
> = 5, pady=5)
> 
>      def switchSuite(self):
>          print 'hi
> 
> --Start.py
> #!/usr/bin/env python
> from Tkinter import *
> from ScrolledListBox import ImageSelection
> 
> class ImageSel(ImageSelection):
>       def __init__(self):
>           ImageSelection.__init__(self)
> 
> class Index(Frame):
>      def __init__(self, parent=None):
>          Frame.__init__(self, parent)
>          Button(self, text='Regression', 
> command=self.buttonOpensImageSelectionWindow).pack(side=TOP,fill=BOTH)
> 
>      def buttonOpensImageSelectionWindow(self):
>          _w = ImageSel()
>          _w.mainloop()
> 
> if __name__ == '__main__':
>   i = Index()
>   i.pack()
>   i.mainloop()
> 
> Not necessarily the best or most correct way, but it should at least get 
> you facing in the right general direction.




More information about the Python-list mailing list