mysql - 如何将 MySQL 数据库中的数据填充到 python 中的树视图中?
问题描述
很抱歉,如果我在错误的部分发布了这个,我是 stackoverflow 的新手,我确实搜索过类似的主题,但没有得到我需要的东西。
所以我想做的是,从mysql数据库中获取表的信息,格式为:((1,google,username1,password1),(2,facebook,username2,password2)......)
并将其填写在具有 4 列网站、用户名、密码的树视图中,如下所示:
我尝试过的是:
#find password
def find_password(selection):
#remove the frame if it already exists
for child in frame.winfo_children():
child.destroy()
#to fill tree with tuples
def show_table(table):
for x in table:
tree.insert("", 0, text=x)
#button1 function
def btn_input_one(text1):
text_input = text1.get("1.0", "end-1c")
connection = mysql.connector.connect(host='localhost',database='suryansh',user='suryansh',password='suryansh')
if connection.is_connected():
cursor = connection.cursor(buffered = True)
cursor.execute("select database();")
#sql queries
create_table_query = "select * from " + text_input
cursor = connection.cursor(buffered = True)
result = cursor.execute(create_table_query)
table = cursor.fetchall()
show_table(table)
这就是我尝试过的,这就是我得到的:
解决方案
一位朋友帮我解决了这个问题,解决方案是:
for x in table:
tree.insert("", "end", text=x[1], values=(x[2], x[3]))
这就是您填充默认列以外的其他列的方式:D
推荐阅读
- spring-boot - 我们如何在 spring-boot 中配置子域?
- android - 如何将活动实例转换为 gson
- syntax-error - 获取语法错误
- c# - 如何测试取消 TokenSource 的方法?
- sublimetext3 - 使 Sublime Text 书签列不敏感
- c# - 用于移动和碰撞对象的性能更好的四叉树
- python - 转变
到'0'和'1' python的字符串 - java - 如果页面上存在该元素,如何出现在控制台中
- java - 如何在后台以特定间隔重复执行java文件?
- c# - 如何在我的代码中实现“if (TargetToFind != null)”以修复“Missing Reference Exception: error message