【发布时间】:2022-12-01 23:09:56
【问题描述】:
I'm making the data stored in mysql workbench come out when I click the search button by clicking one in the dataList, but as shown in the picture below, only the 'Plants' table appears, the 'PlantsMemo' data does not appear, and an error pops up.
the Error is "for RH, LM, TEMP, Tree, Flower, Fruit, min_height, max_height, avg_height, memo_info in allplantmemo:
ValueError: too many values to unpack (expected 10)"
I divided into mysql class and tkinter class
Below is the code I wrote
class final()
# create mysql table code(class final)
def createTables(self):
conn, cursor = self.connect()
self.useGuiDB(cursor)
cursor.execute("CREATE TABLE Plants( \
Plant_ID INT AUTO_INCREMENT, \
date VARCHAR(25) NOT NULL, \
time VARCHAR(25) NOT NULL, \
recorder VARCHAR(25) NOT NULL, \
location VARCHAR(25), \
count INT, \
seed_name VARCHAR(25) NOT NULL, \
PRIMARY KEY (Plant_ID) \
) ENGINE=InnoDB")
cursor.execute("CREATE TABLE PlantsMemo( \
PlantMemo_ID INT AUTO_INCREMENT, \
RH INT, \
LM INT, \
TEMP INT, \
Tree INT, \
Flower INT, \
Fruit INT, \
min_hieght INT,\
max_height INT, \
avg_height INT, \
memo_info VARCHAR(255), \
dataList INT, \
PRIMARY KEY (PlantMemo_ID), \
FOREIGN KEY (dataList) \
REFERENCES Plants(Plant_ID) \
ON DELETE CASCADE \
) ENGINE=InnoDB")
# class final
def searchData(self, ID):
conn, cursor = self.connect()
self.useGuiDB(cursor)
cursor.execute("SELECT * FROM Plants where Plant_ID = ({})".format(ID))
allPlants_1 = cursor.fetchall()
cursor.execute("SELECT * FROM PlantsMemo")
allPlants_2 = cursor.fetchall()
return allPlants_1, allPlants_2
class Program()
# class program
def insert(self, ID):
allplant, allplantmemo = self.final.searchData(ID)
for id_1, date, time, recorder, location, count, seed_name in allplant:
str(id_1)
self.date_Entry.insert(END, date)
self.time_cobbx.insert(END,time)
self.recorder_Entry.insert(END,recorder)
self.RadioVar.set(location)
self.count_combx.insert(END,count)
self.seed_Entry.insert(END,seed_name)
for RH, LM, TEMP, Tree, Flower, Fruit, min_height, max_height, avg_height, memo_info in allplantmemo:
self.RH_spinbx.insert(END, RH)
self.LM_spinbx.insert(END, LM)
self.TEMP_spinbx.insert(END, TEMP)
self.tree_spinbx.insert(END, Tree)
self.flower_spinbx.insert(END, Flower)
self.fruit_spinbx.insert(END, Fruit)
self.min_height_spinbx.insert(END, min_height)
self.max_height_spinbx.insert(END, max_height)
self.avg_height_spinbx.insert(END, avg_height)
self.Memo_txt.insert(END, memo_info)
# search button
def search(self):
ID = self.List_txt.get(ACTIVE)
arr = ID[-1]
self.clear()
self.insert(arr)
I want to appear the data from the 'Plants' table not only but so the 'PlantsMemo' table appear.
【问题讨论】:
-
The table
PlantsMemohas 12 columns, but you just provide 10 variables in the linefor RM, LM, ... in allplantmemo. Missing variables forPlantMemo_IDanddataListcolumns.
标签: mysql tkinter mysql-workbench