I am doing my school project on mysql connectivity with python and my project is on inventory managment
Here I am storing all the databases and the tables of each table in dictionary ex:-'{'database1':('table1','table2')}' and so on. So whenever I need to refer a database or a list of database or tables of selected database I simply use the dictionary to get it.
global database
database = []
global data_table_dict
data_table_dict={}
def startup():
conn = msc.connect(host="localhost", user="root", password="123456")
cursor = conn.cursor()
cursor.execute("show databases")
databasesql_form = cursor.fetchall()
conn.commit()
conn.close()
for i in databasesql_form:
database.append(i[0])
print("all databases", database)
for i in database:
tables = []
conn = msc.connect(host="localhost", user="root", password="123456", database=i)
cursor = conn.cursor()
cursor.execute("show tables")
tablesql_form = cursor.fetchall()
print("All the tables:-", tablesql_form)
conn.commit()
conn.close()
for j in tablesql_form:
tables.append(j[0])
print("The list is:", tables)
data_table_dict.update({i: tables})
print("The dictionary:--", data_table_dict)
startup()
def addnew_category():
def add_database():
conn1 = msc.connect(host="localhost", user="root", password="123456")
cursor1 = conn1.cursor()
cursor1.execute("create database {0}".format(var1.get()))
conn1.commit()
conn1.close()
add_database_window = Tk()
label2 = Label(add_database_window, text="Category Name")
label2.grid(row=0, column=0)
var1 = StringVar()
var1.set(database[0])
option_menu = OptionMenu(add_database_window, var1.get(), *database)
option_menu.grid(row=0, column=1, padx=10, pady=20)
btn1 = Button(add_database_window, text="Add")
btn1.grid(row=1, column=1)
add_database_window.mainloop()
The problem is in the options menu I refered it correctly but when I try to select another option it shows this error:
AttributeError: 'str' object has no attribute 'set'
I don't know why it is showing error.
Thank You! in advance
question from:
https://stackoverflow.com/questions/65859470/getting-errorattributeerror-str-object-has-no-attribute-set 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…