user3576298
user3576298

Reputation: 1

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()

Upvotes: 0

Views: 2136

Answers (1)

Lafexlos
Lafexlos

Reputation: 7735

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.

Upvotes: 1

Related Questions