python script written with pygame, accept user input? [duplicate] - python

This question already has answers here:
How can I create a text input box with Pygame?
(5 answers)
Closed last month.
I made a script with python and pygame. However, I found there are no method in pygame which can provide button or text for giving user input. I just want to make a start, stop, reset button, and with text field floating along the pygame windows to hold user input before the start of the program.
What can I use to take such user input? I don't want to use a config file. Thanks.

I guess that's what you need:
http://www.pygame.org/ftp/contrib/input.html

Related

Does Python have a values registry? [duplicate]

This question already has answers here:
Viewing all defined variables
(10 answers)
Closed 2 months ago.
Im coming from a MatLab background, and started to pick up Python. In matlab it generates a table of the last value of any parameter while excecuting the code. It really helps in debugging.
is there anything simillar in Python, or is ironning the bugs out, soley based on print('...') to see the values of interest?
Well you can use a proper debugger in python. In Pycharm it's the little bug to the right of the run button.
You can then use break points to stop the code at any time. This is done by clicking to the right of the line number.
If your program hits that break point the program will pause.
if your program is in a paused state you can navigate trough your code with these buttons
Some IDEs, for example, PyCharm, provide the ability to debug.

Open() in Python - Does a popup window exist? [duplicate]

This question already has an answer here:
How do I allow a user to select a file?
(1 answer)
Closed 4 years ago.
I am starting to look into Python from a learning perspective and I am finding it nice and easy after Java.
I am currently looking at working with files and I am using the 'with open()' command to make use of the open file only whilst the program is running.
However, all the tutorials I seem to come across only ever seem to hard code either a filename or file path into the open() command.
In Python or any of its libraries - does anyone know of a command I can use to allow the user a pop-up window to navigate and select where the file lives?
Kind Regards
Try using tkinter. tkinter is Python's de-facto standard GUI (Graphical User Interface) package. I will show an example
Either you can ask with this:
a_var = input('select directory of the file')
and then use the a_var to use the directory provided by the user
or
Use tkinter to ask the user to browse to the needed location

Python raw input with arrows [duplicate]

This question already has answers here:
Finding the Values of the Arrow Keys in Python: Why are they triples?
(3 answers)
Closed 6 years ago.
How can I allow the arrows in raw_input()?
There is a better way?
When I write and I use the left arrow, ^[[D appears.
I am using Linux.
If you are Windows, the cursor keys work normally to allow editing of your input. On Linux, I find that I need to import readline to get the input editing module.
If you Google for "python readline" you will get many more hits and suggestions on enhanced editing, tab completion, etc.
Have you tried?
myinput = raw_input("Enter your input ->")
I am using windows , it works fine. Don't have a linux to simulate.
Also, why are you pressing arrow keys? Is it a need for program?
You can simply make arrow using a dash and greater than keys.

"are you sure" exit prompt in python tkinter GUI [duplicate]

This question already has answers here:
Intercept Tkinter "Exit" command?
(5 answers)
Closed 8 years ago.
I have written my first program on Python 3.4, including a GUI using Tkinter. (Hooray!)
I have an option to save input (create a text file and a csv from what they've input), or people can X out of the program without saving the info.
Is there a way to bring up an "are you sure you want to exit without saving?" prompt when people click the X to exit?
Use tkMessageBox maybe.
Here's an example from another query Tkinter askquestion dialog box.

How do I prevent my Python application from automatically closing once reaching the end of code? [duplicate]

This question already has answers here:
How to keep a Python script output window open?
(27 answers)
Closed 8 years ago.
I'm new to programming, especially Python. I'm trying to make an application that converts Fahrenheit to Celsius, but I don't know how to make the program stay open. Whenever it reaches the end of the code, it automatically closes before the user can see his or her results. I'm using Python 2.6.
Well, I guess you mean the terminal that Windows opens for you when you run a python file is closed too fast. You can add raw_input('Press Enter to exit') right before your program would exit. It tells Python to wait for input before exiting.
As the other people say, just ask for input to get it to hold. However, I would recommend running your Python scripts in a different manner in Windows. Using the IDLE IDE (should have come with your distribution), just open the script you want to run and press F5. Then, not only can you see the output for as long as you like, but you can also examine any variables that were assigned interactively. This is very handy especially when you are just starting to program in Python.
You can also run scripts from the command line, but I would recommend use IDLE if you're just starting out.
ask user to enter one more variable and print "Press enter to exit..."

Categories

Resources