如何将单选按钮选择与数组数据联系起来
我正在尝试使用 tkinter python 2.7 编写一个 GUI 可搜索细菌数据库,并将数据库数组嵌入到代码中。通过单选按钮选择某些标准有选择地搜索阵列,然后点击“识别”按钮应该打印出与这些选择匹配的所有细菌的 ID 作为标签。
我在下面发布了非功能性片段 [idbuttonclick(self)]。
代码片段 def idbuttonclick(self) 应该做什么:
1) 搜索名为“data”的矩阵/数组,其中第 1-4 列代表单选按钮字符串变量选项,每行代表细菌 id
2) 选择“data”中的行' 其变量选项与单选按钮选择匹配
3) 如果 ids 数量为 1-20,则打印所选行中数据列 0 中的细菌 ids 作为 self.id_frame 中的标签。否则,打印消息标签“错误:数据不足。”
def idbuttonclick(self):
def column(matrix, i):
if column(data, 1)!=self.gram_option.get(): line.destroy()
if column(data, 2)!=self.meta_option.get(): line.destroy()
if column(data, 3)!=self.cat_option.get(): line.destroy()
if column(data, 4)!=self.oxi_option.get(): line.destroy()
column(data, 0)==id
if id.count >= 20 or id.count == 0:
Label(self.id_frame, text = "Error: Not enough data", background = "white").pack(side=TOP, anchor = N)
else: Label(self.id_frame, text = id, background = "white").pack(side=TOP, anchor = N)
我已经获得了基于单选按钮选择为我提供 id.frame 标签的代码,但仍然无法将单选按钮选择链接到数组中的坐标,然后根据单选按钮/数组坐标匹配提供 id.frame 标签。
它现在具体是一个数组,而不是矩阵,因为矩阵以及列表和元组的列表显然无法使用坐标索引 (i,j) 存储元素。
下面是我的新草稿,其中包括数组和 idbutton 单击命令。
这应该如何运作: 如果选择了单选按钮 self.gram_option=('+'),则同一行内数组第 2 列中具有“+”值的数组第 1 列中的任何细菌名称都应出现在 id.frame 标签中。 因此,标签应为:“醋酸杆菌、假单胞菌”
另外,单击 self.meta_option.get() 应对应于第 2 列,缩小选择范围:“fac anaerobe”值将标记“Acetobacter aceti”,“aerobe”值将标记“Pseudomonas sp”。
data = array([
['Acetobacter aceti','+', 'fac anaerobe', '+', '--'],
['Citrobacter freundii','--', 'fac anaerobe', '+', '--'],
['Pseudomonas sp','+', 'aerobe', '--', '--']])
data.readlines()
def idbuttonclick(self, event):
self.id_frame.destroy()
self.id_frame = Frame(self.main_right_frame, borderwidth=5, height=50, background="white")
self.id_frame.pack(side=TOP, fill=BOTH)
if data[i,1]==self.gram_option.get():
id = data [i,0]
Label(self.id_frame, text = id, background = "white").pack(side=LEFT, anchor = N)
if data[i,2]==self.shape_option.get():
id = data [i,0]
Label(self.id_frame, text = id, background = "white").pack(side=LEFT, anchor = N)
if data[i,3]==self.meta_option.get():
id = data [i,0]
Label(self.id_frame, text = id, background = "white").pack(side=LEFT, anchor = N)
if data[i,4]==self.cat_option.get():
id = data [i,0]
Label(self.id_frame, text = id, background = "white").pack(side=LEFT, anchor = N)
else: Label(self.id_frame, text = 'Error: Not enough data', background = "white").pack(side=LEFT, anchor = N)
如果我没有正确说明我的数组坐标,或者有人知道在 python 代码中安排上述场景的可行方法... 在大约两周的时间里,我收到了关于这个问题的 56 条意见,但没有来自社区的代码编写反馈。希望这个新版本能更好地解决我最初的想法和需要调整的内容。
此致,
杰夫
I'm attempting to write a GUI searchable bacteria database with the database array embedded in the code using tkinter python 2.7. Choosing certain criteria via radiobuttons selectively searches the array, then hitting the 'Identify' button should print out the id of all bacteria which match those selections as a label.
I've posted the nonfunctional snippet [idbuttonclick(self)] below.
What the snippet def idbuttonclick(self) is supposed to do:
1) Search the matrix/array named 'data' for which columns 1-4 represent a radiobutton string variable option and each row a bacteria id
2) Select the rows in 'data' whose variable options match the radiobutton selections
3) Prints the bacteria ids in data column 0 from the selected rows as a label in the self.id_frame if the number of ids is 1-20. Otherwise, print the message label "Error: Not enough data."
def idbuttonclick(self):
def column(matrix, i):
if column(data, 1)!=self.gram_option.get(): line.destroy()
if column(data, 2)!=self.meta_option.get(): line.destroy()
if column(data, 3)!=self.cat_option.get(): line.destroy()
if column(data, 4)!=self.oxi_option.get(): line.destroy()
column(data, 0)==id
if id.count >= 20 or id.count == 0:
Label(self.id_frame, text = "Error: Not enough data", background = "white").pack(side=TOP, anchor = N)
else: Label(self.id_frame, text = id, background = "white").pack(side=TOP, anchor = N)
I've gotten the code to give me id.frame labels based on radiobutton selections, but still can't link the radiobutton selections to coordinates in the array to then provide id.frame labels based on the radiobutton/array coordinate matches.
It is now specifically an array, not a matrix, as matrices and lists of lists and tuples apparently cannot store elements using a coordinate index (i,j).
Here's my new draft below, which includes array and idbutton click command.
How this should work:
Any bacteria name in array column 1 with a '+' value in array column 2 within the same row should appear in the id.frame label if the radiobutton self.gram_option=('+') is selected.
So, the label should read: 'Acetobacter aceti, Pseudomonas sp.'
Additionally clicking self.meta_option.get() should then correspond to column 2, narrowing the selection: a 'fac anaerobe' value would label 'Acetobacter aceti' and an 'aerobe' value would label 'Pseudomonas sp.'
data = array([
['Acetobacter aceti','+', 'fac anaerobe', '+', '--'],
['Citrobacter freundii','--', 'fac anaerobe', '+', '--'],
['Pseudomonas sp','+', 'aerobe', '--', '--']])
data.readlines()
def idbuttonclick(self, event):
self.id_frame.destroy()
self.id_frame = Frame(self.main_right_frame, borderwidth=5, height=50, background="white")
self.id_frame.pack(side=TOP, fill=BOTH)
if data[i,1]==self.gram_option.get():
id = data [i,0]
Label(self.id_frame, text = id, background = "white").pack(side=LEFT, anchor = N)
if data[i,2]==self.shape_option.get():
id = data [i,0]
Label(self.id_frame, text = id, background = "white").pack(side=LEFT, anchor = N)
if data[i,3]==self.meta_option.get():
id = data [i,0]
Label(self.id_frame, text = id, background = "white").pack(side=LEFT, anchor = N)
if data[i,4]==self.cat_option.get():
id = data [i,0]
Label(self.id_frame, text = id, background = "white").pack(side=LEFT, anchor = N)
else: Label(self.id_frame, text = 'Error: Not enough data', background = "white").pack(side=LEFT, anchor = N)
If I'm not stating my array coordinates correctly or someone knows a workable way to arrange the above scenario in python code...
I've gotten 56 views on this question over a period of about two weeks, but no code-writing feedback from the community. Hopefully, this new version better addresses what I originally had in mind and what needs tweaking.
Sincerely,
Jeff
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
该解决方案使用概率比较而不是 + 和 - (即,每个细菌有 X 概率获得 + 分数,1-X 概率获得 - 分数。)但是此代码会将单选按钮绑定到数据矩阵,然后相应地对得分前十名的细菌进行排序。所有的部分都在合作。
This solution uses a probability comparison instead of + and - (i.e., each bacteria has X probability of getting a + score and 1-X probability of getting a - score.) But this code will tie in the radiobuttons to the data matrix and then rank the top ten scoring bacteria accordingly. All the pieces are cooperating.