简体   繁体   中英

how to make remove buttons function for Tkinter grid_remove using python.

I am adding add button, but if i want to remove that widget row& column it will not remove when i call remvoe_material function.

    def remove_material():
            r=7
            global r
            #combo=Pmw.ComboBox(root,label_text='Select Material:',labelpos='w',scrolledlist_items=map(str, a)).grid(row = r, column = 2, sticky = 'w')
            #Entry= Pmw.EntryField(root, labelpos = 'w',label_text = 'Thickness in mm:').grid(row = r, column = 4, sticky = 'w')
            #lable=Tkinter.Label(root,text="mm.Outside").grid(row=r,column=5,sticky='w')
            remove=Tkinter.Button(root,text="Remove",command='').grid(row=r,column=6,sticky='w')
            r=r-1
            #return combo,Entry,lable
            #remove.grid(row=r,column=3)
            #remove.grid_remove()
            remove.grid_forget()
            #remove.grid()

When you are assigning a widget to a variable, you need to grid / pack / place it in another line. Because you can use those methods on tkinter objects.

remove=Tkinter.Button(root,text="Remove",command='')
remove.grid(row=r,column=6,sticky='w')
>>>type(remove)
>>><class 'Tkinter.Button'>

remove=Tkinter.Button(root,text="Remove",command='').grid(row=r,column=6,sticky='w')
>>>type(remove)
>>><class 'NoneType'>  

So this should work.

remove=Tkinter.Button(root,text="Remove",command='')
remove.grid(row=r,column=6,sticky='w')

remove.grid_forget()

EDIT : Your program should give also a syntax error because of global decleration. You need to first define it as global, then assign it a value.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM