Hi all, I played a little to see how one could write gui-building code with Tkinter in a more 'declarative' way, sorta like a DSL, and also - and more importantly - less redundant. After a few iterations I got this:
# code begin top = Tk( 'top' ) # first argument of any widget is the name top.add( Frame( 'frame' ) ) top.frame.add ( Pack( side = 'top' ), Frame ( 'panel1' ), Frame( 'panel2' ), Pack( side = 'bottom' ), # packing change Button( 'button', text='Click Me', command = functools.partial(button_cb, top) ) ) top.frame.panel1.add( Pack( side='left'), Label ( 'label', text="Entry 1 : " ), Entry ( 'entry' ) ) top.frame.panel2.add( Pack( side='left'), Label ( 'label', text="Entry 1 : " ), Entry( 'entry' ) ) top.realize().mainloop() # code end What do you think? I believe it is a nice result, although probbly is not worth the effort (but I was playing and it was fun :-). Advantages: - the GUI layout is quite readable ( that was the main goal ); you could also arrange it depth-first if you like, by chaining the add methods. - the widgets can be reached by traversing the tree hierarchy, in a way that remember tcl (although lazy-finger developers may object the length of the chain ) - the same geometry management can be specified once and used for more than one children in the add method Drawbacks: - yet another layer on the top of tkinter on the top of tcl/tk. - I needed to add realize, which is when all the widgets are created, because you need to create the master before the children. The widget hierarchy should be 'frozen' after that, or things might break To make this code work I had to wrote about 70 lines of python, including blanks, to create the wrapper classes for Button, Label. Entry, Frame, Tk ( all subclasses of Widget, which is the main class of this experiment ), and then again Pack, Place and Grid geometry classes. I will post the code, if anyone is interested, but it is quite obvious. So, again : what do you think ? Ciao ------- FB
_______________________________________________ Tkinter-discuss mailing list Tkinter-discuss@python.org http://mail.python.org/mailman/listinfo/tkinter-discuss