<small id='wdCkg'></small><noframes id='wdCkg'>

    <bdo id='wdCkg'></bdo><ul id='wdCkg'></ul>

    <tfoot id='wdCkg'></tfoot>
    <legend id='wdCkg'><style id='wdCkg'><dir id='wdCkg'><q id='wdCkg'></q></dir></style></legend>
      <i id='wdCkg'><tr id='wdCkg'><dt id='wdCkg'><q id='wdCkg'><span id='wdCkg'><b id='wdCkg'><form id='wdCkg'><ins id='wdCkg'></ins><ul id='wdCkg'></ul><sub id='wdCkg'></sub></form><legend id='wdCkg'></legend><bdo id='wdCkg'><pre id='wdCkg'><center id='wdCkg'></center></pre></bdo></b><th id='wdCkg'></th></span></q></dt></tr></i><div id='wdCkg'><tfoot id='wdCkg'></tfoot><dl id='wdCkg'><fieldset id='wdCkg'></fieldset></dl></div>
    1. 根据“grid_location",按钮有自己的坐标系.方法?

      Buttons have their own coordinate system according to the quot;grid_locationquot; method?(根据“grid_location,按钮有自己的坐标系.方法?)
    2. <legend id='poGEa'><style id='poGEa'><dir id='poGEa'><q id='poGEa'></q></dir></style></legend>
    3. <tfoot id='poGEa'></tfoot>
    4. <i id='poGEa'><tr id='poGEa'><dt id='poGEa'><q id='poGEa'><span id='poGEa'><b id='poGEa'><form id='poGEa'><ins id='poGEa'></ins><ul id='poGEa'></ul><sub id='poGEa'></sub></form><legend id='poGEa'></legend><bdo id='poGEa'><pre id='poGEa'><center id='poGEa'></center></pre></bdo></b><th id='poGEa'></th></span></q></dt></tr></i><div id='poGEa'><tfoot id='poGEa'></tfoot><dl id='poGEa'><fieldset id='poGEa'></fieldset></dl></div>

          <small id='poGEa'></small><noframes id='poGEa'>

            <bdo id='poGEa'></bdo><ul id='poGEa'></ul>
                <tbody id='poGEa'></tbody>

                本文介绍了根据“grid_location",按钮有自己的坐标系.方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我正在尝试使用 Tkinter 中 Grid Geometry Manager 中的 grid_location 方法,但似乎我做错了什么.

                I'm trying to use the grid_location method, from the Grid Geometry Manager, in Tkinter, but it seems that I'm doing something wrong.

                这是我的代码:

                from tkinter import * 
                
                
                root = Tk()
                
                b=Button(root, text="00")
                b.grid(row=0, column=0)
                b2=Button(root, text="11")
                b2.grid(row=1, column=1)
                b3=Button(root, text="22")
                b3.grid(row=2, column=2)
                b4=Button(root, text="33")
                b4.grid(row=3, column=3)
                b5=Button(root, text="44")
                b5.grid(row=4, column=4)
                
                def mouse(event):
                    print(event.x, event.y)
                    print(root.grid_location(event.x, event.y))
                
                root.bind("<Button-1>", mouse)
                
                root.mainloop()
                

                当我在按钮外部单击时,它可以工作,但是当我在任何按钮内部单击时,似乎每个按钮都有自己的坐标系.所以,每个按钮都在 (0, 0) 单元格上,尽管在代码中,它们都在规则网格上.

                When I click outside the Buttons, it works, but when I click inside of any Button, it seems that each button has its own coordinate system. So, each button is on the (0, 0) cell, despite that in the code, they are on a regular grid.

                推荐答案

                你说得对,每个按钮都有自己的坐标系".不过,更准确地说,event.xevent.y 值是相对于与事件关联的小部件而不是小部件的父窗口或根窗口.

                You are correct that each button "has it's own coordinate system". More accurately, though, the event.x and event.y values are relative to the widget associated with the event rather than the widget's parent or the root window.

                如果您确实需要小部件所在的行和列,可以使用 grid_info 来获取与事件关联的小部件的行和列.例如:

                If you really do need the row and column that the widget is in you can use grid_info to get the row and column of the widget associated with the event. For example:

                def mouse(event):
                    grid_info = event.widget.grid_info()
                    print("row:", grid_info["row"], "column:", grid_info["column"])
                

                这篇关于根据“grid_location",按钮有自己的坐标系.方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                相关文档推荐

                groupby multiple coords along a single dimension in xarray(在xarray中按单个维度的多个坐标分组)
                Group by and Sum in Pandas without losing columns(Pandas中的GROUP BY AND SUM不丢失列)
                Group by + New Column + Grab value former row based on conditionals(GROUP BY+新列+基于条件的前一行抓取值)
                Groupby and interpolate in Pandas(PANDA中的Groupby算法和插值算法)
                Pandas - Group Rows based on a column and replace NaN with non-null values(PANAS-基于列对行进行分组,并将NaN替换为非空值)
                Grouping pandas DataFrame by 10 minute intervals(按10分钟间隔对 pandas 数据帧进行分组)

                  <small id='gxy4e'></small><noframes id='gxy4e'>

                    • <i id='gxy4e'><tr id='gxy4e'><dt id='gxy4e'><q id='gxy4e'><span id='gxy4e'><b id='gxy4e'><form id='gxy4e'><ins id='gxy4e'></ins><ul id='gxy4e'></ul><sub id='gxy4e'></sub></form><legend id='gxy4e'></legend><bdo id='gxy4e'><pre id='gxy4e'><center id='gxy4e'></center></pre></bdo></b><th id='gxy4e'></th></span></q></dt></tr></i><div id='gxy4e'><tfoot id='gxy4e'></tfoot><dl id='gxy4e'><fieldset id='gxy4e'></fieldset></dl></div>

                    • <tfoot id='gxy4e'></tfoot>
                      <legend id='gxy4e'><style id='gxy4e'><dir id='gxy4e'><q id='gxy4e'></q></dir></style></legend>
                          <bdo id='gxy4e'></bdo><ul id='gxy4e'></ul>

                            <tbody id='gxy4e'></tbody>