A problem with ivx development

dhn8112 注册会员
2023-02-27 13:11

This answer quotes ChatGPT

You can add a checkbox column to the table container, with one checkbox for each row. Users can check one or more checkboxes to select data that needs to be submitted to another database. Then, during the commit operation, it iterates through all the rows in the table container, checking that the check box for each row is checked, and if it is checked, it commits the data for that row to another database.

The exact implementation of

may vary from case to case, but here is a simple example code to help you understand the process:

import sqlite3
import tkinter as tk
from tkinter import ttk

# 连接源数据库
conn_src = sqlite3.connect('source.db')
c_src = conn_src.cursor()

# 连接目标数据库
conn_dest = sqlite3.connect('destination.db')
c_dest = conn_dest.cursor()

# 创建表格容器和复选框列
root = tk.Tk()
table = ttk.Treeview(root)
table['columns'] = ('name', 'age', 'selected')
table.column('name', width=100)
table.column('age', width=50)
table.column('selected', width=50)
table.heading('name', text='Name')
table.heading('age', text='Age')
table.heading('selected', text='Selected')
for i in range(5):
    table.insert('', i, text=str(i), values=('Name {}'.format(i), i+20, False))

# 提交选中的数据到目标数据库
def submit_selected_data():
    for row in table.get_children():
        values = table.item(row)['values']
        if values[2]:
            c_dest.execute("INSERT INTO people (name, age) VALUES (?, ?)", (values[0], values[1]))
    print('Selected data submitted')

# 勾选复选框时更新数据
def update_selected_data(event):
    item = table.focus()
    values = table.item(item)['values']
    values = (values[0], values[1], not values[2])
    table.item(item, values=values)

table.bind('', update_selected_data)

# 显示表格和提交按钮
submit_button = tk.Button(root, text='Submit selected data', command=submit_selected_data)


panchaoyu1 注册会员
2023-02-27 13:11

The girl refers to bing and GPT :
To select a piece of data from a database and then submit it to another database, you need to use the knowledge of the front and back ends.

First, in the front page, we can use a table to display the data from the database and add a box to the table to let the user check the data to be submitted.

        <tr v-for="item in list">
            <td><input type="checkbox" :value="item.id" v-model= "selectIds">td>

Where selectIds is an array that stores the id that the user checked.

Then, on the back-end page, we can use Ajax requests to send the selectIds to the server side, which queries the corresponding data in the database against the selectIds contents. The data is then saved to another database.

   url: '/saveToDataBase',  // 请求地址 
   type: 'post',   // 请求方式 
   data: {  // 请求参数 
       selectIds: selectIds   // 用户勾选的id 
   success: function(data){   // 请求成功回调函数 

       // 根据返回的data处理业务逻辑 


The answer is not easy, so take it.

cruff05 注册会员
2023-02-27 13:11

The general idea is that you start by adding a selection column to the table container so that the user can select which rows to submit. You then add an event listener to the check box or radio box that fires when the user checks or selects a line. When the user submits data, it traverses the rows in the table container, finds the selected row, and submits its data to the target database.

// 获取表格容器控件
var grid = document.getElementById("myGrid");

// 遍历表格中的数据行
for (var i = 0; i < grid.rows.length; i++) {
  var row = grid.rows[i];

  // 获取该行的复选框控件
  var checkbox = row.cells[0].getElementsByTagName("input")[0];

  // 如果该行的复选框被选中,则提交该行的数据
  if (checkbox.checked) {
    var data = {
      // 获取该行的数据,并组织成一个对象
      // ...
    // 提交数据到目标数据库
    // ...

About the Author

Question Info

Publish Time
2023-02-27 13:11
Update Time
2023-02-27 13:11