Click here to Skip to main content
15,890,947 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
please help me to create a list of tuple like this with one button. when the button click you will insert the first item and so on


def button():

records_to_insert = [(4, 'HP Pavilion Power', 1999, '2019-01-11'), first item
(5, 'MSI WS75 9TL-496', 5799, '2019-02-27'), second item
(6, 'Microsoft Surface', 2330, '2019-07-23')] third item

i want to create a list of tuple like this .......using a function and append... i using a entry box and get() the item to entry box place like this....

What I have tried:

i try using a list and append but the input is not combining.....if i click the button the first item appear like that so on

[(4, 'HP Pavilion Power', 1999, '2019-01-11')]
[(5, 'MSI WS75 9TL-496', 5799, '2019-02-27')]
[(6, 'Microsoft Surface', 2330, '2019-07-23')]


i want the code appear like this

records_to_insert = [(4, 'HP Pavilion Power', 1999, '2019-01-11'), first item
(5, 'MSI WS75 9TL-496', 5799, '2019-02-27'), second item
(6, 'Microsoft Surface', 2330, '2019-07-23')] third item
Posted
Comments
Richard MacCutchan 7-Jul-22 8:50am    
You need to show the actual code that you are using. I would guess that you are creating a new list each time you input some data, but that is just a guess.
Member 15696171 8-Jul-22 5:09am    
when i input a data, the data add to a list and when you input another data that data will insert to that list to create a new list....
Richard MacCutchan 8-Jul-22 5:20am    
Please show your actual code. We cannot guess what you are doing.
Member 15696171 8-Jul-22 5:33am    
-1



def Addmultipledata():

global data_list1, data_list2
global count



global count,

first1 = fn_entry1.get()
last1 = ln_entry1.get()
ID1 = ID_entry1.get()
Address1 = Address_entry1.get()
city1 = City_entry1.get()
Zipcode1 = Zipcode_entry1.get()


data_list= [ ]
data_list.clear()
data_list.append(first1)
data_list.append(last1)
data_list.append(ID1)
data_list.append(Address1)
data_list.append(city1)
data_list.append(Zipcode1)

data_list2 = []
data_list2.append(data_list)
data_list1=tuple(data_list1)

for x in data_list2:
my_tree.insert(parent='', index='end',iid=count,text="", values=(x[0],x[1],x[2],x[3],x[4],x[5]))
count = count + 1

fn_entry1.delete(0, END)
ln_entry1.delete(0, END)
ID_entry.delete(0, END)
Address_entry1.delete(0, END)
City_entry1.delete(0, END)
Zipcode_entry1.delete(0, END)

def addmultipledatamysql():

mydb = mysql.connector.connect(
host="localhost",
user="root",
password="12345",
database="SCHOOLREG"
)

my_cursor = mydb.cursor()
sql_command = """INSERT INTO Studentreg(First_Name,Last_Name,Student_id, Address,CITY,Zipcode) VALUES(%s,%s,%s,%s,%s,%s) """
# values = (record[0], record[1], record[3], record[4], record[5])
results = my_cursor.executemany(sql_command, data_list2)

mydb.commit()

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900