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
Related
I’d like to create a restricted folder/ file explorer in Python (I have version 2.7.9, but I don’t mind changing that) for Windows.
Essentially, I want to initially specify the folder to which the code opens. For example, the code should initially open to: C:\Users\myName\Desktop\myDemoFolder (the user must not know this folder simply by looking at the GUI).
The user must be able to browse downwards (deeper into folders) and backwards (but only up to the initial folder to which the code opens). The user must be able to click to open a file (for example: pdf), and the file must automatically open in its default application.
An example of what I’d like is presented in figure 1. (The look of the interface is not important)
Currently, I am able to get figure 2 using the code presented here:
from Tkinter import Tk
from tkFileDialog import askopenfilename
Tk().withdraw()
filename = askopenfilename()
print(filename)
Research has indicated that it is not possible to change the default buttons in Tkinter windows. Is this true? If it can’t be done with Tkinter (and that’s fine), how else can we do it?
I’d happily choose simple, non-Tkinter code (perhaps using wxPython’s wx.GenericDirCtrl()) rather than elaborate Tkinter code, but no restrictive libraries please.
A modular design approach is not needed. I’d rather have simple (functional) code that is shorter than object-oriented code.
I was trying to do the same thing when I realized that maybe you could create all the buttons you need and then set the color of the buttons you don't need to your background color using:
button-name.config(bg = "background-color")
Just change the "button-name" to your button's name and set "background-color" to the background color!
I would like to create a GUI that pops up asking where to download a file using python. I would like it to be similar to the interface that Google Chrome uses when downloading a file as that looks pretty standard. Is there a default module or add on that I can use to create thus GUI? or will I have to create myself? any help would be appreciated.
If You mean the dialog window, in which You chose where to put file, it's tkinter.filedialog (https://docs.python.org/3/library/tkinter.html), which would give the most native look and feel.
But if You mean the dialog, in which You chose whether to save file in default location or specify another one, there's no such widget, but You may build it on Your own. For that case You probably should dig into Chromium sources, to determine how exactly it acts(https://chromium.googlesource.com/)
There are a number of GUI toolkits you could use, including:
Kivy (modern touch-enabled)
Tkinter (bundled with Python)
These have file chooser widgets, which you could use that would provide standard-looking interfaces to your file system.
How do you want to run this program?
This question already has answers here:
How to make a gui in python [closed]
(10 answers)
Closed 7 years ago.
I need to create a Form which accepts some user details and accordingly run a Python script and generate excel files. The code to generate the excel files is ready.
But, I need to create a GUI which asks for the details. I do not want this to be a web application, so I'm not using Django. Is there any other way I can create a standalone exe form (in Python or other languages) that can call my script?
I would recommend using something like TkInter or PyQt. These will allow you to design a user interface in Python and then grab values from them and attach events to them (The UI Objects).
Here is a little TkInter tutorial, and here is a PyQT tutorial on form layouts.
Personally, I would recommend PyQT (4 or 5) as there is a visual designer for the UI, which may speed up development.
I'm not even sure what these would be called? I used to write them in ADA running on VAX-VMS!
I want to make a simple menu-driven application that would let me display menus and use the cursor keys to navigate around them, choose items and navigate around the app. All fully old school text based.
I want to be able to take over the whole terminal window and display stuff in different places.
Is this possible in Python?
Check out the Python HOWTO on Curses Programming with Python and here is the library reference.
Another easy to use library is Urwid - Console User Interface Library.
http://excess.org/urwid/
http://excess.org/urwid/examples.html
Yes, have a look at the different curses implementations.
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..."