为Python Turtle TextInput设置重点

发布于 2025-01-24 07:31:18 字数 407 浏览 3 评论 0原文

在我的Python项目(游戏)中,我有一个功能可以获取播放器(2)名称:

def get_names(self):
    self.lp_name = turtle.textinput("Left Player", "Enter your Name")
    self.rp_name = turtle.textinput("Right Player", "Enter your Name")

在此处输入图像描述/a>

对于第一个(左播放器)TextInput字段处于活动状态 - 具有焦点,但对第二个(正确的播放器)没有焦点

In my python project (game) I have a function to get player (2) names:

def get_names(self):
    self.lp_name = turtle.textinput("Left Player", "Enter your Name")
    self.rp_name = turtle.textinput("Right Player", "Enter your Name")

enter image description here

For the first (Left Player) the textinput field is active - has focus but NOT for the second (Right Player)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

渔村楼浪 2025-01-31 07:31:18

TextInput字段不活动,因为当您单击“确定”时,焦点从主窗口转移到弹出窗口。
(尝试单击主窗口,您可以看到TextInput字段变得活跃。)

因此您可以使用screen.tracer()函数在每个范围之后更新主屏幕输入。

样本就像:

screen = turtle.Screen()

def get_names(self):

    self.lp_name = turtle.textinput("Left Player", "Enter your Name")

    screen.tracer(1) #Refreshes the turtle window and sets focus to the main window.

    self.rp_name = turtle.textinput("Right Player", "Enter your Name")

这应该有效。

The textinput field is not active because the focus shifts from the Main Window to the popup window when you click 'OK'.
(try clicking on the main window and you can see the textinput field becoming active.)

So you could use a screen.tracer() function to update the main screen after each input.

sample would be like :

screen = turtle.Screen()

def get_names(self):

    self.lp_name = turtle.textinput("Left Player", "Enter your Name")

    screen.tracer(1) #Refreshes the turtle window and sets focus to the main window.

    self.rp_name = turtle.textinput("Right Player", "Enter your Name")

This should work.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文