Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/282.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/design-patterns/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 将单击事件绑定到标签下方的框架_Python_Tkinter - Fatal编程技术网

Python 将单击事件绑定到标签下方的框架

Python 将单击事件绑定到标签下方的框架,python,tkinter,Python,Tkinter,我有一个有三个标签的框架,我想点击框架中的任何地方来触发一个事件。不幸的是,标签位于框架顶部,点击没有注册 frame=tk.Frame(root) frame.pack() frame.bind("<1>", function) L1=tk.Label(frame, text="Label_1") L1.pack() L2=tk.Label(frame, text="Label_2") L2.pack() L3=tk.Label(frame, text="Label_3") L3

我有一个有三个标签的框架,我想点击框架中的任何地方来触发一个事件。不幸的是,标签位于框架顶部,点击没有注册

frame=tk.Frame(root)
frame.pack()
frame.bind("<1>", function)

L1=tk.Label(frame, text="Label_1")
L1.pack()
L2=tk.Label(frame, text="Label_2")
L2.pack()
L3=tk.Label(frame, text="Label_3")
L3.pack()
frame=tk.frame(根)
frame.pack()
frame.bind(“,函数)
L1=tk.Label(框架,text=“Label_1”)
L1.pack()
L2=tk.Label(框架,text=“Label_2”)
L2.pack()
L3=tk.Label(框架,text=“Label_3”)
L3.pack()
是否需要将单击事件绑定到每个标签

为清晰起见进行编辑:我有一个框架,其中有三个标签。我之所以这样做,是因为这是我能够正确格式化三个字符串的唯一方法(仅一个Label对象不允许格式化单个部分)。我希望单击框架中的任意位置以触发事件,即单击任意标签、任意位置并触发相同的事件。现在我可以看到三种解决方案:

  • 我找到了一种方法,通过单击标签来单击框架
  • 我找到了将三个标签格式化为一个标签的方法。但我认为不可能像printf那样格式化标签
  • 我将相同的命令绑定到每个标签 潜在的第四种解决方案:我创建一个从按钮继承的框架。也不确定这是否可行。也许我可以给一个按钮添加多个标签


    还有其他方法吗?

    尝试使用
    Canvas
    而不是
    Frame
    Canvas
    应该允许
    .bind('
    ),并且能够使用@stovfl使用
    Canvas
    布局多个“文本”项,非常有效,谢谢!