python - Tkinter adding label frames -


i have been trying failed below. have 1 label frame entry boxes. want add button user can add multiple frames in tool along entry boxes , buttons below existing label frame.and when new frame added text box below should shifted. code tkinter below:

from tkinter import * root=tk() root.title("cime") step = labelframe(root,text="enter details:") step.grid(row=0, columnspan=7, sticky='w',padx=5, pady=5, ipadx=5, ipady=5) label(step,text="competitors",font = "arial 8 bold italic").grid(row=0,sticky='e', padx=5, pady=2) label(step,text="keywords",font = "arial 8 bold italic").grid(row=1,sticky='e', padx=5, pady=2) label(step,text="project name",font = "arial 8 bold italic").grid(row=2,sticky='e', padx=5, pady=2) e1 = entry(step) e2=entry(step) e3=entry(step) e1.grid(row=0,column=1,columnspan=7, sticky="we", pady=3,padx=5) e2.grid(row=1,column=1,columnspan=7, sticky="we", pady=3,padx=5) e3.grid(row=2,column=1,columnspan=7, sticky="we", pady=3,padx=5) tex = text(master=root) scr=scrollbar(root,orient =vertical,command=tex.yview) scr.grid(padx=1, column=7, rowspan=15, columnspan=1, sticky=ns) tex.grid(row = 4,column=1) tex.config(yscrollcommand=scr.set,font=('arial', 8, 'bold', 'italic')) #tex['yscrollcommand'] = sb.set button(step,text ="search words",width=10,font = "arial 8 bold    italic",activebackground="red",command=roll).grid(row=3,column=0,sticky=w,pady=4,padx=5) button(step,text="google search",width=10,font = "arial 8 bold italic",command = links).grid(row=3,column=2,sticky=w,pady=4,padx=5) button(step,text="extraxt text",width=10,font = "arial 8 bold italic",command = create).grid(row=3,column=4,sticky=w,pady=4,padx=5) mainloop() 

enter image description here

define function generate enter detail label frame. , call in callback function of new button.

from tkinter import * def roll(): pass def links(): pass def create(): pass root=tk() root.title("cime")  rows = 0 def create_detail_frame():     global rows     step = labelframe(root,text="enter details:")     step.grid(row=rows, columnspan=7, sticky='w',padx=5, pady=5, ipadx=5, ipady=5)     label(step,text="competitors",font = "arial 8 bold italic").grid(row=0,sticky='e', padx=5, pady=2)     label(step,text="keywords",font = "arial 8 bold italic").grid(row=1,sticky='e', padx=5, pady=2)     label(step,text="project name",font = "arial 8 bold italic").grid(row=2,sticky='e', padx=5, pady=2)     e1 = entry(step)     e2 = entry(step)     e3 = entry(step)     e1.grid(row=0,column=1,columnspan=7, sticky="we", pady=3,padx=5)     e2.grid(row=1,column=1,columnspan=7, sticky="we", pady=3,padx=5)     e3.grid(row=2,column=1,columnspan=7, sticky="we", pady=3,padx=5)     button(step,text ="search words",width=10,font = "arial 8 bold    italic",activebackground="red",command=roll).grid(row=3,column=0,sticky=w,pady=4,padx=5)     button(step,text="google search",width=10,font = "arial 8 bold italic",command=links).grid(row=3,column=2,sticky=w,pady=4,padx=5)     button(step,text="extraxt text",width=10,font = "arial 8 bold italic",command = create).grid(row=3,column=4,sticky=w,pady=4,padx=5)     rows += 1      # reposition text, scroll     #scr.grid_forget()     #tex.grid_forget()     #scr.grid(row=rows, padx=1, column=7, rowspan=15, columnspan=1, sticky=ns)     #tex.grid(row=rows,column=1)      # reposition text, scroll     scr.grid(row=rows)     tex.grid(row=rows)  tex = text(master=root) scr=scrollbar(root,orient =vertical,command=tex.yview) scr.grid(row=1, padx=1, column=7, rowspan=15, columnspan=1, sticky=ns) tex.grid(row=1,column=1) tex.config(yscrollcommand=scr.set,font=('arial', 8, 'bold', 'italic'))  button(root, text='add detail frame', command=create_detail_frame).grid(row=0, column=7) create_detail_frame()  mainloop() 

note: used global variable rows keep track of how many grid rows there above text widget.


Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -