Drag and drop files in Tkinter GUI - python

I am fairly new to Python and is stuck at a problem. I am using Python 3.7 and intend to add a "drag-and-drop" functionality to my GUI.
I have some files that needs to be read, thus i am looking for an option where i can simply drag those files to a particular area in my GUI and file name or Path is read by my program.
Being a newbie a detailed answer or a code would be highly helpful.
Thanks

Unfortunately, tkinter only supports experimental widget drag and drop, nothing else. I ran into similar problems trying to make a complex GUI.
I would look into wxPython. It's complex, Object Oriented, and daunting, but has and unbelievable amount of features that reward you for learning it. Including file drag and drop.
Look at the wxPython thumbnails at https://wxpython.org/Phoenix/docs/html/gallery.html for images of what the widgets look like. The thumbnails include images for about half of the available widgets. The images are also a bit out of date.
Look at pronounced https://pythonlibrary.org or https://zetcode.com for the best tutorials. After them, your best resource is Google and the forums.

Related

VTK Render Mouse Interaction (Python)

I want to visualize one or more STL file(s) using a vtk render viewport inside my application. I was able to get it all running with this example here: https://kitware.github.io/vtk-examples/site/Python/IO/ReadSTL/
My question is as follows: I have a mouse to control it and it is just unbelievable how bad default the controls of the camera are. It is almost impossible to get the model rotated intentionally or focus on a certain part. I am confused as I could not find any topic here or elsewhere discussing this. Normally I would read through other threads to find an answer, but there doesn't seem to be any. So, maybe you can point me to an approach or even certain functions of how I can change these settings, that would be really great! Basically I want to mimic the camera behavior of say, Paraview or a common CAD tool. Like zooming with mouse wheel, rotating with RMB and holding down the wheel to pan.
Some background on my project: I have written a python program and created a quite ok UI using tkinter. However, recently I was thinking of rewriting some basic parts of it and also upgrading everything visually and in terms of handling. So, I want to move to Qt widgets and, there shall be a VTK rendering viewport inside my application to show some of the stuff that can be interacted with.
I was able to find a solution in the tutorials. By explicitly defining the vtkInteractorStyle with
style = vtk.vtkInteractorStyleTrackballCamera()
The handling is just as I wanted it to be.

Visual Basic like GUI for Python with arrays of text boxes and labels

There are lots of GUI environments for Python like Qt, tKinter, wx, PySimpleGUI, etc. so I have not been able to go through very many of them. I would like to know if there is one which is
somewhat similar to Visual Basic's (drag and drop and resize),
allows for arrays of textboxes and labels.
It should preferably be open source,
should create stand alone *.exe files,
and not requiring browsers.
The closest match to your requirements is probably PySimpleGUI. Doesn't have drag and drop, but you don't really need it. It takes 1 line of code to configure and place a widget into your window. You easily make an "array of textboxes and labels". Runs on tkinter or Qt.
Would that there were a simple drag and drop GUi builder for Python!
You might try appJar. It's not drag and drop but it seems pretty straightforward.
QtDesigner is drag and drop. It's part of the PyQT suite. QtDesigner creates XML (.ui) files which can then be translated to .py files. Michael Herrmann's site
shows how to do this with a minimum amount of overhead.
I personally recommend my project https://github.com/cdhigh/tkinter-designer.
tkinter-designer implemented a add-on in VB6, you can design your GUI in VB6 (drag and drop, resize, align, color, key-bind,...), and then this add-on generate a complete code frame. what you will do is add logic code in event method like coding in VB.
PS: You can install nano version of vb6.

Create a basic Python interface to save images drawn with a mouse

I am working on the following project and I am having really difficulties in finding the right way of doing that. I would like to build in Python (but I am open to other possibilities) a very basic interface that allows the user to draw with the mouse (or the pen if used on a surface laptop) something and then save the image. Ideally I would like this to work on a website or at least in a jupyter notebook (at least I imagine this to be utterly difficult).
Anyone can point me in the right direction? The goal would be to use the images as input to a neural network model to demonstrate its result with real life examples.
I am looking at tk but I don't seem to find much in terms of examples.
Thanks in advance, Umberto
I'd take a look at pyautogui to capture the mouse location then "draw" it in matplotlib -- should be able to do this in a loop. You'll want to watch the tkinter window size to sync the mouse coordinates with the relative location.
Why not just have your script open create a new blank img and automatically open it with paint - then read it on close? Seems easier than creating a drawing GUI.
Have a look at my Github repository which have exactly what you need.
Link : CanvasDraw Repo
Depending on the complexity you could either use tkinter which is a package for complex GUIs or something from the gaming community like pygames. You have user input and graphical output so libraries made for games will do what you want but provide way more stuff then you need. This site might help you: Drawing Libarys
Also the answere draw-on-python-tkinter-canvas-using-mouse-and-obtain-points-to-a-list might help you.

Creating ribbon menus with tkinter

Is there a way to create menu's such as the one provided in WordPad on Windows 7 with Tkinter?
I haven't found anything like it, and it would improve the looks on my scripts immensely.
What you are describing is what Microsoft calls a ribbon. No, there is nothing built-in to tkinter to provide such a menu. Most of the building blocks are there to emulate it (notebooks, buttons, dropdowns, etc), but you'll have to do a fair amount of work to get it to work exactly like a ribbon.
The consensus on ribbons seem to be that they only aid usability when you have a very large amount of controls that you need to present to the user. That is why you see such ribbons on tools like Word and Excel, but not so much on browsers, notepad, etc. I would advise that unless your app needs such a rich toolbar, adding one won't actually improve the usability of your application.

Python: OSX Library for fast full screen jpg/png display

Frustrated by lack of a simple ACDSee equivalent for OS X, I'm looking to hack one up for myself. I'm looking for a gui library that accommodates:
Full screen image display
High quality image fit-to-screen (for display)
Low memory usage
Fast display
Reasonable learning curve (the simpler the better)
Looks like there are several choices, so which is the best? Here are some I've run across:
PyOpenGL
PyGame
PyQT
wxpython
I don't have any particular experience with any of these, nor any strong desire to become an expert - I'm looking for the simplest solution.
What do you recommend?
[Update]
For those not familiar with ACDSee, here's what it does that I care about:
Simple list/thubmnail display of images in a directory
Sort by name/size/type
Ability to view images full screen
Single-key delete while viewing full screen
Move to next/previous image while viewing full screen
Ability to select a group of images for:
move to / copy to directory
delete
resize
ACDSee has a bunch of niceties as well, such as remembering directories you've moved images to in the past, remembering your resize settings, displaying the total size of the images you've selected, etc.
I've tried most of the options I could find (including Xee) and none of them quite get there. Please keep in mind that this is a programming/library question, not a criticism of any of the existing tools.
I will recommend using wxPython to create such a viewer, wxPython is easy to learn, free, cross platform and blends well in OSX. Even if you want to use pyopengl, wxPython would be good with pyopengl.
see such tutorials http://showmedo.com/videotutorials/video?name=1790000&fromSeriesID=179
and there is already cornice written in wxpython/PIL, may be you can modify that. It has been inspired by the famous Windows-only ACDSee :)
it's not an answer to your coding question but for (a big part of) the lack of ACDsee equivalent (requires OSX 10.5+):
Simple list/thubmnail display of images in a directory: Finder.app
Sort by name/size/type: Finder.app will do name & type, not image size (but does file size)
Ability to view images full screen: quick preview (spacebar / eye icon)
Single-key delete while viewing full screen: command-backspace while viewing in quickpreview, both windowed and fullscreen
Move to next/previous image while viewing full screen: both quickprewiew (after selecting a group of images or whole directory with cmd-a) and Preview.app
Ability to select a group of images for[...]: Finder.app will does all but resize
seems like you have everything except resize just pressing the spacebar while in finder.
Preview.app will resize both a single image or multiple ones in one batch.
Use an App like Picasa (now available on mac). Use AppleScript through Python to control it from your application.
Failing that, use PyObjC to create Cocoa image display component and dialogs, and so on.
I ended up using PyGame, has been pretty good so far.

Categories

Resources