My_w.I am doing a chat client using a treeview with multiple columns in Python. My_w.columnconfigure(0,weight=1) # first column with weight My_w.rowconfigure(1,weight=1) # second row with weight My_w.rowconfigure(0,weight=1) # first row with weight While placing the widgets in the grid we have to use the sticky option to expand the widget in all four directions sticky='nsew' to occupy the available space. Here we are assigning weight to each row and columns to match the expansion and contraction of the main or parent window. Zoom In and Zoom out widgets along with the window can be achieved by using the rowconfigure() and columnconfigure(). We kept three Labels inside top frame.Įxpanding & contracting widgets along with the main windowĮxpand & contract of widgets on change in geometry of the parent Tkinter window using rowconfigure We can use rowconfigure() columnfigure() outside the main window. Using rowconfigure columnfigure inside frame Let us add one right side column ( frame_right ) with different weight.įrame_right=tk.Frame(my_w,bg='lightblue')įrame_id(row=0,column=0,rowspan=3,sticky='WENS')įrame_id(row=0,column=2,rowspan=3,sticky='WENS') My_w.rowconfigure(1, weight=8) # change weight to 4įrame_left=tk.Frame(my_w,bg='lightgreen')įrame_top.grid(row=0,column=1,sticky='WENS')įrame_id(row=1,column=1,sticky='WENS')įrame_id(row=2,column=1,sticky='WENS')įrame_id(row=0,column=0, rowspan=3,sticky='WENS') Here let us add one left column ( frame_left ) We can assign weight to different columns by using columnconfigure(). My_w.rowconfigure(2, weight=1) # 10% of total height My_w.rowconfigure(1, weight=8) # 80% of total height My_w.rowconfigure(0, weight=1) # 10% of total height Here all three rows are equally distributed as their weight=1, so each one takes 33% of total space available. My_w.rowconfigure(1, weight=1) # change weight to 4 My_w.columnconfigure(0,weight=1) # column weight 100% In above code there are some lines commented ( removed ), by introducing these lines we can assign weightage to each row and full weightage given to single column ( column =0 ) 元=tk.Label(frame_bottom,text='frame_bottom') L2=tk.Label(frame_middle,text='frame_middle') #my_w.rowconfigure(1, weight=1) # change weight to 4įrame_top.grid(row=0,column=0, sticky='WENS')įrame_id(row=1,column=0,sticky='WENS')įrame_id(row=2,column=0,sticky='WENS') My_w.geometry("410x200") # Size of the window Here we used Frame as containers to hold group of widgets. Here is an example without using rowconfigure() and columnconfigure() Tkinter rowconfigure & columnconfigure to assign relative weight to rows and columns width & height
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |