gpt4 book ai didi

python - Tkinter - 坐标

转载 作者:行者123 更新时间:2023-12-01 04:10:55 26 4
gpt4 key购买 nike

我正在用 Pi2Go 机器人制作一个小项目,它将从超声波传感器获取数据,然后如果它看到一个物体,则放置一个 X,并放置 O 它当前所在的位置,我有两个问题:如何在 tkinter 上设置坐标位置?例如,我想在 0,0 或 120,120 处插入文本。

其次:如何让 tkinter 不断更新我正在构建的 map 干杯!

最佳答案

我只是拼凑了一些代码,向您简要介绍如何使用place几何管理器。如需进一步说明,请参阅代码中的注释:

#!/usr/bin/env python3
# coding: utf-8

from tkinter import *


# init our application's root window
root = Tk()
root.geometry('480x480')


# let's provide same sample coordinates with the desired text as tuples in a list
coords = [(30,30,'X'), (90,90,'X'), (120,120,'X'), (240,240,'X'), (270,270,'X'), (360,360,'O')]


# interate through the coords list and read the coordinates and the text of each tuple
for c in coords:
l = Label(root, text=c[2])
l.place(x=c[0], y=c[1])


# start a loop over the application
root.mainloop()

我使用的是Python 3。如果您使用的是Python 2,则需要将tkinter更改为Tkinter。如果您需要将我的代码移植到 Python 2,这应该可以解决问题。

关于python - Tkinter - 坐标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34970482/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com