python - 调用函数时增加小部件创建位置的问题
问题描述
我试图让这个函数分别创建一个标签和2个按钮,每次调用这个函数时,都会在下一行创建3个小部件(直接在前3个小部件下方)。
但是,我不确定为什么尽管计数器增加,但项目仍然在同一行上创建(在调用函数时有效地重叠在同一行上)。
def fetch_quick(self, entries):
for entry in entries:
text = entry[1].get()
print(text)
exec("app._framea" + str(self._qqq+7) + "= tk.Frame(app._master, bg='white')")
exec("app._framea" + str(self._qqq+7) + ".grid(row=" + str(self._qqq+6) + ")")
exec("self.queue_entry_quick" + str(self._qqq) + " = Label(app._framea" + str(self._qqq+7) + ", text='1 '+text +' 0 a few seconds ago')")
exec("self.queue_entry_quick" + str(self._qqq) + ".grid(row=" + str(self._qqq) + ")")
exec("self._Button" + str(self._qqq) + " = Button(app._framea" + str(self._qqq+7) + ", text = self._qqq, width = 2, command=app._framea" + str(self._qqq+7) + ".destroy, bg='red')")
exec("self._Buttonb" + str(self._qqq) + " = Button(app._framea" + str(self._qqq+7) + ", text = self._qqq, width = 2, command=app._framea" + str(self._qqq+7) + ".destroy, bg='green')")
exec("self._Button" + str(self._qqq) + ".grid(row=" + str(self._qqq) + ", column=1)")
exec("self._Button" + str(self._qqq) + ".bind('<Button-1>',self.call)")
exec("self._Buttonb" + str(self._qqq) + ".grid(row=" + str(self._qqq) + ", column=2)")
exec("self._Buttonb" + str(self._qqq) + ".bind('<Button-1>',self.call)")
abcd.append(text)
self._qqq += 1
print(self._qqq)
我认为这可能是小部件的创建位置(在网格上)被预先设置为所有小部件的第 0 行的问题,因此它不会在每次调用函数时更新 self._qqq。如果是这种情况,我仍然不确定该怎么做
解决方案
推荐阅读
- reactjs - 我可以在不丢失实现的情况下使用 React 测试库和 Jest 监视 mapDispatchToProps 函数吗?
- excel - VBA SetSourceData 函数有效但给出错误?
- python-pptx - 使用 Python pptx 更改幻灯片布局
- python - python(pandas)中的Dataframe有问题
- powershell - Dockerfile RUN 在基于 Ubuntu 的映像上调用 powershell
- java - 为什么我从数据库中获得的价值不公开?
- javascript - 如何使样式化的 ReacJs Header 组件具有粘性或固定在顶部?
- javascript - 从 JSON 对象中提取深层数据
- python - 如何在不使用函数 train_test_split 的情况下将数据拆分为测试和训练?
- vba - 在 VBA 中,无法从工作簿事件处理程序 Workbook_BeforeClose 或 Workbook_Deactivate() 调用工作表中的子例程