加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Python > 正文

python – pygame – 如何从get_pos中分割X和Y坐标

发布时间:2020-12-20 12:30:39 所属栏目:Python 来源:网络整理
导读:对不起,所有这些问题,我真的不打算打扰你们. 但我遇到的问题是我不知道如何从pygame get_pos函数中分割X和Y坐标,因为get_pos将X和Y坐标合二为一. 有没有办法将它们分成单独的变量? 提前致谢 解决方法 get_pos返回一个元组.你可以做一个序列解包: x,y = pyg
对不起,所有这些问题,我真的不打算打扰你们.

但我遇到的问题是我不知道如何从pygame get_pos函数中分割X和Y坐标,因为get_pos将X和Y坐标合二为一.

有没有办法将它们分成单独的变量?

提前致谢

解决方法

get_pos返回一个元组.你可以做一个序列解包:

x,y = pygame.mouse.get_pos()

引用一个伟大的人(和Python documentation):

This is called,appropriately enough,sequence unpacking and works for any sequence on the right-hand side. Sequence unpacking requires the list of variables on the left to have the same number of elements as the length of the sequence. Note that multiple assignment is really just a combination of tuple packing and sequence unpacking

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读