Is there a way to change the location of a text box in turtle? It always shows up in the top left for me, but I want it in the bottom center

泄露秘密 提交于 2021-02-09 11:13:28

问题


import turtle

screen = turtle.Screen()

global answer

answer = screen.textinput("Welcome to the game", "What's your name?")

Here is a screenshot of what comes up. I can't seem to find anything describing a way to edit the box at all. I'm also looking for ways to edit the overall appearance of the box, as it's intended purpose is for dialogue in the game I'm working on.


回答1:


The window with the input is made with tkinter. You can make your own function that makes it.

Here is a sample of your code:

import turtle
from tkinter import *

screen = turtle.Screen()

global answer

def textinput(title, question):
    message = Tk()
    message.title(str(title))
    message.geometry("350x200")
    l = Label(message, text = str(question))
    l.pack()#you can place it wherever you want
    e = Entry(message)#customize all you want
    e.pack()
    def submit(event = "<Return>"):
        global answer
        answer = e.get()
        message.destroy()
    b = Button(message, text = "submit", command = submit)
    b.pack()
    b.bind_all("<Return>", submit)
    message.mainloop()
answer = textinput("Welcome to the game", "What's your name?")

You can customize this window in any way. Like changing the button color, entry color, position, etc.

Hope this helps!!



来源:https://stackoverflow.com/questions/61175289/is-there-a-way-to-change-the-location-of-a-text-box-in-turtle-it-always-shows-u

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!