Quantcast
Channel: Scripting - McNeel Forum
Viewing all articles
Browse latest Browse all 5938

Eto Add, Remove buttons dynamically

$
0
0

Hello
How to remove the new button created?

import Eto.Drawing as drawing
import Eto.Forms as forms

class MyDialog(forms.Dialog):

    def __init__(self):
        self.Title = 'Add and delete controls'
        self.ClientSize = drawing.Size(300, 500)
        self.Padding = drawing.Padding(10)
        self.Resizable = False

        self.buttonAdd = forms.Button(Text = 'Add button')
        self.buttonAdd.Click += self.ButtonAddClick
        
        self.buttonRemove = forms.Button(Text = 'Remove button')
        self.buttonRemove.Click += self.ButtonRemoveClick
        
        self.layout = forms.DynamicLayout()
        self.layout.AddRow(self.buttonAdd, self.buttonRemove)
        self.layout.AddRow(None)
        self.Content = self.layout
        
        self.count = 0
        self.buttons = []

    def AddButton(self):
        self.count += 1
        self.button = forms.Button(Text = 'Add button'+str(self.count))
        self.layout.AddRow(self.button)
        self.buttons.append(self.button)
        self.layout.AddRow(None)
        self.layout.Create()
        
    def RemoveButton(self):
        self.count += 1
        self.layout.Remove(self.buttons[-1])
        #self.layout.AddRow(None)
        self.layout.Create()

    def ButtonAddClick(self, sender, e):
        self.AddButton()
    
    def ButtonRemoveClick(self, sender, e):
        self.RemoveButton()


def TestMyDialog():
    dialog = MyDialog()
    dialog.ShowModal()


if __name__ == '__main__':
    TestMyDialog()

5 posts - 3 participants

Read full topic


Viewing all articles
Browse latest Browse all 5938

Trending Articles