1

So I am working on my first "large" python project (second GUI), and it is a simple SQLite database manager. As of now, this is what it looks like... Current state of database manager.

At the top, as you can see, there is a change table button and a drop-down to select what table you wish to switch to.

What I want to do is to remove the button, replace it with an ordenary label(This is easy to do), and then have the OptionMenu change the table a different one is selected automatically.

This is what I have for the changing.

def change(self, root, c, tableToChangeTo, table, list_columns):
    table = tableToChangeTo.get()
    cursor = c.execute('select Rowid, * from ' + table)
    list_columns = [description[0] for description in cursor.description]

    self.clear()
    self.table(root, c, table, list_columns)
    self.addGui(root, c, table, list_columns)
    self.editGui(root, c, table, list_columns)
    self.delGui(root, c, table, list_columns)
    self.changeGui(root, c, table, list_columns)


def changeGui(self, root, c, table, list_columns):
    gridRow = self.rowTotal
    self.changeButton = Button(root, text="Change Table", command= lambda: self.change(root, c, var, table, list_columns))
    self.changeButton.grid(row = 0 , column = 0)

    var = StringVar(root)
    var.set(table)

    options = {""}
    global tableList
    ta = tableList

    for t in ta:
        options.add(t)

    self.changeOption = OptionMenu(root, var, *options)
    self.changeOption.grid(row = 0, column = 1)

So to make it short and sweet, I want to make it where when you select another table, it will automatically run the change method. The big problem is I can not seem to figure out how to make a method an event while at the same time being able to pass variables to it.

So thank you for any help, and if you need anything else, let me know!

1 Answer 1

1

For anyone else having the same problem as me, I was able to get mine working by using this line of code.

self.changeOption = OptionMenu(root, var, *options, command= lambda event: self.change(event,root, c, var, table, list_columns))
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.