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

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.

Related

Tkinter opens instantly subprocess instead of waiting for button click [duplicate]

This question already has answers here:
Why is my Button's command executed immediately when I create the Button, and not when I click it? [duplicate]
(5 answers)
Closed 7 months ago.
I'm working on a code editor based on nano. I've decided to make GUI for it, and the GUI language I chose is Python. I'm trying to make a button that opens batch files on Tkinter. I did so by importing import subprocess. Now, I created a button that opens the batch file with subprocess:
ttk.Button(frm, text="New Session", command=subprocess.run(['csession.bat']) ).grid(column=0, row=1)
Little problem is, when I launch the file, the subprocess action instantly gets executed instead of waiting for the user to click. I'm using VSCode and also debugging in VSCode (if that does any difference).
you need to use lambda if you want to define the command this way.
you can also create a function and set the command to run it.
import tkinter as tk
from tkinter import ttk
import subprocess
def runBat():
subprocess.run(['foo.bat'])
root = tk.Tk()
ttk.Button(root,text="text",command= lambda: subprocess.run(['foo.bat'])).pack()
ttk.Button(root,text="text2",command=runBat).pack()
root.mainloop()

Is there any way to prioritise a window in Tkinter?

Let's say you have quite a few windows into a process of registering a person's data. You then have a confirmation window at the end that needs to be closed before doing anything else (the window should either be closed by pressing 'Submit' or 'Cancelled'). Is there a way how to do this in tkinter python? The only example I could find to actually give a visual of what I mean is in the properties of a file (https://imgur.com/a/DO6cvlw)

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 script written with pygame, accept user input? [duplicate]

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

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