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?
Related
There is a user created GUI which is an .exe that loads a DLL. This GUI has a bunch of sliders, check boxes etc. I would like to move two sliders at the same time using python automatically without me using my mouse to move the sliders. I would like to know the python modules that an be used to achieve this purpose.
You can try using SikuliX.
It can be used to automate mouse or keyboard actions based on pattern matching. It is originally developed for Java I think, but it can be used with Python.
Basically, anything you can do yourself manually can be done with it.
The developer seems to be pretty active, so you can easily seek help from him if you have issues.
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!
Problem
I'm trying to make a gui in python that displays two directories in two side-by-side panels and their contents (via tree, thumbnails, list, etc), which then allows the user to either:
drag files between both panels
select files to transfer (manually and via script), and transfer after user input
The point is to automate as much of the process as possible, but allow the user to verify each file's final transfer.
Is this possible? Which python gui library would be ideal for this? I'm just looking for a general direction, since I really don't know where to begin looking.
Current workaround
I have a python script that will sort mail into subfolders based on client, and then iterates through each client, simultaneously opening mail\<client> and the client's main file directory in explorer. I drag each file to its appropriate <main>\<client\<subfolder>, close the two windows, press 'enter' in IDLE, and it moves on to the next client. Tedious, but it's a rough implementation.
System info
Windows XP, Python 2.7
Well, you could implement a custom drag-and-drop with any GUI framework, so you might consider using Tkinter, since it's built-in to the standard Python library.
If you need to be able to drag-and-drop between applications, it's a bit more complicated, but supposedly can be achieved with Tkinter, although you might prefer to use wxPython, for which there's an example on the wiki.
For anything file related I would use the Python os module, http://docs.python.org/2/library/os.html
I am using Tkinter with Python 2.6 and 2.7 for programming graphic user interfaces.
These User Interfaces contain dialogs for opening files and saving data from the tkFileDialog module. I would like to adapt the dialogs and add some further entry widgets e.g. for letting the user leave comments.
Is there any way for doing so?
It seems that the file dialogs are taken directly from the operating system. In Tkinter they are derived from the Dialog class in the tkCommonDialog module and call the tk.call("tk_getSaveFile") method of a frame widget (in this case for saving data).
I could not find out where this method is defined.
call method is defined in _tkinter.c, but there is nothing interesting for your particular task there. It just calls a Tcl command, and the command tk_getSaveFile does all the work.
And yes, when there is a native file dialog on the operating system, tk_getSaveFile uses them (e.g. GetSaveFileName is used on Windows). It could be possible to add widgets there, but not without tampering with C sources of Tk. If you're sure that your target uses non-native Tk dialogs, you could add something to its widget hierarchy by hacking ::tk::dialog::file:: procedure from Tk (see library/tkfbox.tcl).
I would rather take an alternative implementation of tk_getSaveFile, written in pure Tcl/Tk and never using the OS facility. This way, we can be sure that its layout is the same for all OSes, and it won't suddenly change with a new version of Tk. It's still far from trivial to provide a convenient API for python around it, but at least, it is possible.
I had to get rid of the canvasx/y statements. That line now simply reads set item [$data(canvas) find closest $x $y], which works well. $data(canvas) canvasx $x for its own works well but not in connection with find closest, neither if it is written in two lines.
I'm looking for a cross-platform way of making my Python script process a file's path by implementing a drag n drop method. At the moment I manually go to the terminal and use the sys.argv method:
python myscript.py /Python/myfile.xls
However this is slow and "techy". Ideally I would a quick and interactive way of allowing a file be processed by my Python script. I primarily need this to work for Mac but cross-platform would be better.
If you want to use Tkinter, have a look at the Tkinter DnD binding from here http://klappnase.bubble.org/TkinterDnD/index.html
When run, the binding shows an example with a listbox that allows you to drag a file on to it.
Do you want to drag and drop the myfile.xls onto your python script within your file navigator ? Say Finder or whatever on Mac, Explorer on Win, Nautilus etc. ? In that case there will not be a simple cross-platform solution, given that you will have to hook into different software on different systems.
For a Mac specific solution try AppleScript - here is a sample
And for something Pythonic there is http://appscript.sourceforge.net/ , http://docs.python.org/library/macosa.html
Otherwise the solution is in the answer above. Use a custom GUI built in Tk, or wx or QT. You can look up their respective documentation for drag and drop, they do have cross-platform ways of doing it.
It'd be easiest to just write a small GUI with Tkinter or something similar and have the user select a file from within the GUI. Something along these lines:
import tkFileDialog
f = tkFileDialog.askopenfilename()
# Go on from there; f is a handle to the file that the user picked
I'm not aware of any cross platform methods to get a script to work with drag and drop, however. This is probably easier, though.