0

我无法弄清楚如何从级联上下文菜单更新标签文本。我有菜单,但我无法用我想要的文本更新标签。

def main_context_menu(self):
        self.mnu1 = tk.Menu(self.main_frme, tearoff=0)
        self.mnu2 = tk.Menu(self.main_frme, tearoff=0)
        self.mnu1.add_cascade(label='Overwrite Type', menu=self.mnu2)
        self.mnu2.add_command(label='Bar Beer', command=self.context_menu_command)
        self.mnu2.add_command(label='Store Beer', command=self.context_menu_command)
        self.mnu2.add_command(label='Vapors', command=self.context_menu_command)
        self.mnu2.add_command(label='Cigarettes', command=self.context_menu_command)
        self.mnu2.add_command(label='Gas', command=self.context_menu_command)
        self.mnu2.add_command(label='Misc.', command=self.context_menu_command)
        self.mnu2.add_command(label='Bills', command=self.context_menu_command)

def do_context_menu1(self, event):
        try:
            self.mnu1.tk_popup(event.x_root, event.y_root)
        finally:
            self.mnu1.grab_release()

    def do_context_menu2(self, event):
        print('go')
        self.c_type = event.widget
        print(self.c_type)

def context_menu_command(self):
        self.lblt.configure(text=self.c_type)

self.lblt = tk.Label(self.grid_frme, text=exp_type,
                        width=13, height=2, bg='white')
        self.lblt.grid(row=self.row, column=2)
        self.lblt.bind('<Button-3>', self.do_context_menu1)
        self.mnu2.bind('<Button-1>', self.do_context_menu2)

那是从更大的脚本中摘录的业务端。这是我尝试过的。标签不会更新。我究竟做错了什么?对不起格式。复制并粘贴 BS。我没有时间在这里正确缩进。

4

0 回答 0