应该显示哪个按钮

时间:2017-03-30 06:03:25

标签: python tkinter

假设我们有很多带有指定文本和按钮的按钮。位置。

例如,我们的按钮是{' main',' report',' memory',' bill',...}, 现在我们有一个数组来确定哪个按钮应该可见。

例如z1 = [' report',' bill'],此数组的内容可以是其他按钮。在您的观点中,我该如何编写代码?我应该将每个按钮的文本与" z1"进行比较。数组,在定义每个按钮之前?这是不合理的,因为按钮的数量很多。

这是我的示例代码:

    z1=['report','bills','setting']

    self.button = Button(self.master,text="memory", command=self.ouvrir)
    self.button.grid(row=1, column=1)

    self.button2 = Button(self.master,text="report", command=self.tabluh)
    self.button2.grid(row=1, column=2)


    self.button3 = Button(self.master,text="setting", command=self.new_window)
    self.button3.grid(row=1, column=3)

    self.button4 = Button(self.master,text="calibration", command=self.cal)
    self.button4.grid(row=1, column=4)


    self.button5 = Button(self.master,text="empty weight", command=self.weighing)
    self.button5.grid(row=1, column=5)

    self.button6 = Button(self.master,text="bills", command=self.history)
    self.button6.grid(row=1, column=6) 

    self.button7 = Button(self.master,text="full weight", command=self.full)
    self.button7.grid(row=1, column=7)

1 个答案:

答案 0 :(得分:0)

执行此操作的一种方法是将命令作为值存储在字典中,将文本存储为键。如果您为GUI提供包含您想要查看的键的列表,他将从中选择正确的键。接下来,您将动态创建按钮。

亲切的问候,S

xlab(expression(Delta))