Python:如何在消息框中获取输入框? [英] Python: How to get an entry box within a message box?

查看:749
本文介绍了Python:如何在消息框中获取输入框?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只是意识到我在游戏开始时并没有要求用户提供他们的名字.所以我尝试了这段代码:

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)

但是它不起作用.

如何在游戏开始时弹出一个消息框,显示欢迎使用Math泡泡,您叫什么名字?"然后,用户输入他们的姓名,然后按OK.将会弹出另一个消息框,提示您好 _ ,按开始按钮开始".我想保存用户名,以便在获胜者"消息框中也可以显示他们的姓名

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

推荐答案

您可以使用tkinter.simpledialog函数askstring.

from tkinter.simpledialog import askstring
from tkinter.messagebox import showinfo
name = askstring('Name', 'What is your name?')
showinfo('Hello!', 'Hi, {}'.format(name))

这篇关于Python:如何在消息框中获取输入框?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆