You can read all contents of this book at our site below ... Thank you for taking this book. This book introduce you a library for tkinter building layout with XML file. # Creat instance of Gui ( Gui is a Class we introduce ). # Parameter is a object to get 'Callback Notification'. # Give anything you like. gui = Gui ( self )
# Creat tkinter.Tk instance tk_root = tk.Tk()
# Let's call 'build' function to build layout. # params : parent widget and layout file path. # return : dict ( instance_tree . show you how to use later ) instance_tree = gui.build ( tk_root , 'layout.xml' )
# display tkinter.Tk tk_root.mainloop () That's all . Speedy , Easy , Simple . # We can get 'Widget Instances' from XML file with 'Path' like 'frame/button' # instance_tree is a dict like ... # { path1 : list1 , path2 : list2 , ... } list_of_buttons = instance_tree [ 'frame/button' ]
# To get Button instance from list of Buttons button1 = list_of_buttons [ 0 ] button2 = list_of_buttons [ 1 ] Example of XML file . ( To avoid unintentional characters , I use two-byte characters below ...) <!-- Example of Style Settings --> < style name = "N.TLabel" background = "blue" font = "Arial,20" /> < style name = "N.TButton" font = "serif,20" /> ・・・ <!-- Example of Label Widget --> < label text = "N Python Gui Library" style="N.TLabel"> < /label > ・・・ <!-- Example of Button Widget --> < button text = "click me" style="N.TButton"> < command name = "onclicked" /> < /button > [Point 1] We can define style with style tag .
[Point 2] We can set style to widgets with writing tag name of style to style attribute of widget.
[Point 3] We can bind 'Command' with 'Button' using 'command' tag.