从tkinter导入* 导入psycopg2 导入csv 将熊猫作为pd导入
data = [] 行= [] conn = psycopg2.connect(“ dbname ='ditest'user ='postgres'host ='localhost'password ='blob'”) cur = conn.cursor()
cur.execute(“从information_schema.tables中选择table_name,而table_schema ='blob'“) data = cur.fetchall()
master = Tk() master.title(“ Postgre Exports”)
变量= StringVar(主) variable.set(data [0])
e1 = Label(master,text =“单击表名称以获取导出内容”,font =(“ Arial Bold”,10)) e1.grid(row = 5,column = 2)
e2 =标签(master,text =“ Loading .....”,font =(“ Arial”,10),bg =“ red”,fg =“ white”) e2.grid(row = 4,column = 2)
w = OptionMenu(主菜单,变量,*数据) w.grid(row = 6,column = 2)
def table(): 名称= variable.get() 打印(名称)
def列(): cur.execute(“从table_name为blob的information_schema.columns中选择column_name。%s”%name) 行= cur.fetchall() 使用open(“ C:/ temp / Postgre Exports / test.csv”,'w',newline ='')作为文件: file.writelines(rows)
button = Button(主菜单,文本=“选择表”,command =表) button.grid(row = 7,column = 2)
button = Button(主菜单,文本=“ details”,command =列) button.grid(row = 8,column = 2)
mainloop()
cur.execute(“从information_schema.columns中选择column_name,其中table_name为xynergy。%s”%name) NameError:名称“名称”未定义
我试图创建一个UI,在该UI中,从表列表中,首先我使用下拉选择按钮选择一个表,然后使用明细按钮想要将列名检索到一个csv文件中。