我有一个类,可以从客户按下按钮后显示的队列中创建按钮列表。
但是,我有一个命令,该命令旨在在按下时从队列中删除项目,但是该命令的内容无法运行或从队列中直观地删除该项目。此命令为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)
答案 0 :(得分:1)
使用tkinter按钮调用函数的标准方法如下
myButton = Button(master, text="Press Me", command=myFunction)
myFunction是要调用的函数的名称。