7

I just realised I hadn't asked the user for their name at the start of the game. So I tried this code:

 Label(root, text="What is you name?").grid(row=0, column=0)
 e1 = self.Entry(root)
 e1.self.grid(row = 0, column=1)

But its not working.

How do I get a message box to pop up in the start of the game saying "Welcome to Math bubbles, what is your name?" The user then types in their name and presses ok. Another message box will pop up saying "Hello _, press the start button to begin". I would like to save the users name so that in the Winner message box I could display their name as well

Pokemon_SL
  • 289
  • 2
  • 6
  • 11

2 Answers2

11

You can use the tkinter.simpledialog function askstring.

from tkinter.simpledialog import askstring
from tkinter.messagebox import showinfo
name = askstring('Name', 'What is your name?')
showinfo('Hello!', 'Hi, {}'.format(name))
Ben Last
  • 141
  • 1
  • 5
  • Simple and great method! Do you know how to adapt it for a password input dialog? – Basj Dec 02 '19 at 09:57
  • This doesn't work for me. I get: AttributeError: 'NoneType' object has no attribute 'winfo_viewable' – Jason Jun 24 '21 at 16:20
  • @BenLast This works quite well for my needs but I have a question. Can I change the buttons from `Ok` and `Cancel` to `Confirm` and `Cancel`? Is it also possible to give the popup a special font? – TRCK Jun 15 '22 at 20:25
1

You can create a Dialog box as modal dialog then put an entry box and some buttons to handle your custom dialog messages inside them and show it.

Reza Ebrahimi
  • 3,623
  • 2
  • 27
  • 41