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

Viewed 1173
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 Answers

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!!

Related