运行后运行Python Tkinter运行命令

时间:2019-12-12 12:24:38

标签: python-3.x oop tkinter

我有一个类,可以从客户按下按钮后显示的队列中创建按钮列表。

但是,我有一个命令,该命令旨在在按下时从队列中删除项目,但是该命令的内容无法运行或从队列中直观地删除该项目。此命令为orderFulfilled()。按下时是否可以使用按钮运行该功能?

class MyFirstGUI:
def __init__(self, master):
    self.master = master
    master.title("A simple GUI")

    #self.baristaServed = StringVar()


    self.completedButton = Button(master,text="Complete",width=30,height=5,bg="green", command = MyFirstGUI.orderFulfilled)
    self.completedButton.pack(side=BOTTOM)



    self.barista1 = Button(master,text="Barista 1: Daniel",width=30,height=5)
    self.barista1.pack(side=BOTTOM)
    self.barista2 = Button(master,text="Barista 2: Josh",width=30,height=5)
    self.barista2.pack(side=BOTTOM)

    self.items = []


    for item in selfService.queue1.queue:
        self.button = Button(master,text=item,bg="red", width=35)
        #self.button.bind('<Button-1>', self.baristaServedWhat)
        self.button.pack(side=TOP)
        self.items.append(self.button)


    def orderFulfilled(self):
        print('01')
        selfService.queue1.dequeue()
        self.button = self.items.pop(-1)
        self.button.pack_forget()
        print(selfService.queue1.queue)

1 个答案:

答案 0 :(得分:1)

使用tkinter按钮调用函数的标准方法如下

   myButton = Button(master, text="Press Me", command=myFunction)

myFunction是要调用的函数的名称。