0
votes

I am currently stepping through the tkinter tutorial at python-course.eu. Is it possible to close an entry widget without killing the program? What I am trying to do is incorporate the tkinter entry box into a pygame program such that the program asks for the players name via an entry box and then closes once the text has been entered. The game should then continue. Is this possible?

What I would like to do is:

-create a pygame surface

-open a tkinter entry widget on top of that surface

-get the users name

-close the tkinter widget

-write text using pygame onto the surface that incorporates the user's name

What is stumping me is the fact that the tkinter examples on python-course.eu all end with a mainloop() statement while I would like pygame to have an event loop so that I can expand the program. I anticipate that the widget creation would occur prior to dropping into the event loop. This is where I am stuck :-(

1
I have very limited experience with tkinter and none trying to use it in conjunction with pygame honestly, but I but I believe they can't both run in the same window. I think you could run a tkinter window to pull user data, close it and then create a pygame window but I honestly have never tried. Obviously that wouldn't be the most fluid experience, there may be pygame user input modules out there that'd be more useful. - oxrock

1 Answers

2
votes

rather than trying to mix two GUI libraries in the same window, if a prompt is acceptable you could use:

import tkinter as tk
from tkinter import simpledialog
root = tk.Tk() # needed to prevent extra window being created by dialog
root.withdraw() # hide window as not needed
username = simpledialog.askstring('Username', 'Enter username:')
root.destroy()