首页 > 解决方案 > 调用函数时增加小部件创建位置的问题

问题描述

我试图让这个函数分别创建一个标签和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。如果是这种情况,我仍然不确定该怎么做

标签: pythonuser-interfacetkintergrid

解决方案


推荐阅读