Tkinter: How to make a system tray application? - python

i have a small application. I want my target users(windows,linux) to be able to start and exit the application from the system tray. I intend to use Tkinter because of its low footprint but, i dont know how to implement it.
Can tkinter do this or are there better alternatives. I need a GUI library that won't change my 1MB program to a 5MB program.
Please sample codes will be appreciated
Thanks

I don't know any direct examples but I found a TCL/Tk extension to use the systray over here http://wiki.tcl.tk/4090 and a page on the wiki giving information on how to use TCL/Tk extensions from Tkinter.
On a more general note, you might want to consider using a more "advanced" toolkit (like wx) that provides things like systray usage etc. natively.

Related

Is it possible to style Python GUI like you would style HTML with CSS?

I work a lot with HTML & CSS for Web Development, and I've only recently transitioned to Python for software development. I've done some of the basics with Python, my proudest moment being I programmed a calculator through Python using the TKinter, but I'm going to be honest with you it's quite ugly. I know how to change the foreground and background color, but that's about it. I was sort of hoping there was a way to style Python like you would style HTML with CSS. Is something like this possible?
I don't know if this is too broad of a question, but I really just need some sort of answer. Even a link to some sort of YouTube video to get me down the right path would be nice. I would also like to learn how to do other GUI style's like transitions, hover effects, and keyframes, but that's for another question.
Inside of python your options are quite less, but never none. You have options starting from ttk from tkinter, which kind of gives a windows 7 theme and with ttkthemes you get more themes for tkinter. But if your planning to go on for a more modern GUI, using HTML and CSS and JS, then you do have Eel for python. There is also a python wrapper for Qt called PyQt which also provides not so bad design. And also Kivy which can also gives you some kind of modern looks. Using tkinter is mainly for simple projects and it has its own limitations. But one of the limitation is your imagination and designing skill, for example here is a GUI I made with tkinter:
It does not look top of the mark or something, but it kind of looks better than traditional looks with tkinter.
First off, Web Design with CSS is a lot prettier, in Python you have less options.
But there is an editor called QT Designer, it lets you create GUIs and use them in your C++ or Python script. You may give it a try.
Keith Galli made a youtube tutorial on a Python GUI with TKinter which doesn't look that bad, regarding it's made with Python.

Drag and drop files in Tkinter GUI

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.

Python widget/cursor detection?

Beginner python learner here. I have a question that I have tried to Google but I just can't come up with the proper way to ask in just a few words (partly because I don't know the right terminology.)
How do I get python to detect other widgets? For example, if I wanted a script to check and see when I click my mouse if that click put focus on an entry widget on a (for example) website. I've been trying to get it to work in Tkinter and I can't figure out even where to begin.
I've seen this:
focus_displayof(self)
Return the widget which has currently the focus on the
display where this widget is located.
But the return value for that function seems to be some ambiguous long number I can't decipher, plus it only works in its own application.
Any direction would be much appreciated. :)
Do you mean inside your own GUI code, or some other application's/website's?
Sounds like you're looking for a GUI driver, or GUI test/automation driver. There are tons of these, some great, some awful, many abandoned. If you tell us more about what you want that will help narrow down the choices.
Is this for testing, or automation, or are you going to drive the mouse and button yourself and just want something to observe what is going on under the hood in the GUI?
>How do I get Python to detect other widgets?
On a machine, or in a browser? If in a machine, which platform: Linux/Windows (which)/Mac?
If in a browser, which browser (and major version)?
> But the return value for that function seems to be some ambiguous long number I can't decipher
Using longs as resource handles is par for the course, although good GUI drivers also work with string/regex matching on window and button names.
> plus it only works in its own application.
What do you mean, and what are you expecting it to return you? You should be able to look up that GUI object and access its title. Look for a GUI driver that works with window and button names.
Here is one list, read it through and see what sounds useful. I have used AutoIt under Win32, it's great, widely-used and actively-maintained; it can be called from Python (via subprocess).
Here are comparisons by the author of PyWinAuto on his and similar tools. Give a read to his criticisms of its structure from 2010. If none of these is what you want, at least you now have the vocabulary to tell us what would be...

Python GUI with custom render/drawing

I am looking for a Python GUI library that I can rewrite the rendering / drawing.
It has to support basic widgets (buttons, combo boxes, list boxes, text editors, scrolls,), layout management, event handling
The thing that I am looking for is to use my custom Direct3D and OpenGL renderer for all of the GUI's drawing / rendering.
edit suggested by S.Lott: I need to use this GUI for a 3D editor, since I have to drag and drop a lot of things from the GUI elements to the 3d render area, I wanted to use a GUI system that renders with Direct3D (preffered) or OpenGL. It also has to have a nice look. It is difficult to achieve this with GUI's like WPF, since WPF does not have a handle. Also it needs to be absolutly free for commercial use.
edit: I would also like to use the rendering context I initialized for the 3d part in my application
I don't know what are you working at, so maybe this is not what you're looking for, but:
Have you considered using Blender + its Game Engine?
It supports Python scripting, and provides some APIs to create "standard" GUIs too, while allowing you to do a lot of cool stuff with 3d models. This could be especially useful if your application does a lot of 3d models manipulation..
Then you can "compile" it (it just builds the all-in-one package containing all the dependencies, in a way similar to what py2exe does) for any platform you need.
You can use Qt Scene Framework with OpenGL rendering. There are many examples on Nokia site.
The best Python GUI toolkit is wxPython (also known as wxWidgets).
This is not merely my opinion, see also: wxPython quotes
wxPython is the best and most mature
cross-platform GUI toolkit, given a
number of constraints. The only reason
wxPython isn't the standard Python GUI
toolkit is that Tkinter was there
first. -- Guido van Rossum
I can't say how easy or hard it would be to add your own renderer.
There are OpenGL bindings in Python that will get you 3D rendering. Personally, I'd use wxpython as your 'gui' manager and use the bindings to do opengl for the rest. Wx has the necessary demos (check the wxpython demos installation) and information in their GLCanvas demos.
Another sample code is here too.
You might find PyClutter useful.

Integrating a C applet into a Python app (GTK)

I've got a Python/GTK project I've been working on for a while, and some of the functionality I want already exists in Gnome panel applets. Based on my reading, panel applets are already in a subclass of the standard GTK Bin, so I would think there'd be a way that I can use the C-based GTK objects in my Python-based application.
For instance, I've got the fish applet in /usr/lib/gnome-panel/fish-applet-2 as a binary
Can I do some GTK magic to get that object so it can be embedded into my Python/GTK gui?
I'm not expecting a step-by-step walkthrough, but if anyone can point me in the right direction, I'd appreciate it.
The code for applets in gnome panel is quite complex. It's based on the gnome Bonobo framework (which in turn is based on CORBA). But now the whole thing is in a bit of a flux because gnome is moving away from Bonobo to a new dbus-based design. So if it's loading existing gnome panel applets you want you should absolutely use the code from gnome panel to do it. There is (or at least was) an example program included that does nothing but load an applet into a window.
If you want to display a widget from one of your own programs (a custom applet) inside another of your programs it's much easier. There are a set of widgets called GtkSocket and GtkPlug for this purpose. Of course the to programs doesn't need to run on the same machine. But there is always the delicate problem of getting them together in the first place.

Categories

Resources